Kori
Hey
I'm new to django and I'm really stuck when running a migration I get UNIQUE key constraint failed on the onetoonefield connected to user
Could anyone please help me
inchidi
Kori
I make the migrations it's ok
When I do the migrate that's when I get the error
inchidi
may i see your last migration file?
Kori
Ok lemme send you
inchidi
use dpaste.de or pastebin btw
Maz
what are some interesting Advanced Django topics i would want to take a look at?
Maz
Maz
Also, if i need to show the time an object was deleted from the db, how would i go about doing it?
Maz
e.g. a Patient model....how do i display when a patient record is deleted?
Kori
https://pastebin.com/AfXPauWq
inchidi
providing default value for your Employees.user field
Maz
Maz
okay,
inchidi
you will realize the cons of that approach on your journey
Kori
inchidi
what error produced?
Kori
Same error
IntegrityError: UNIQUE constraint failed
inchidi
ah so you have so many employees data
inchidi
so, what user do you want for each employees data you have?
inchidi
any specific rules?
Kori
when a user registers for the site I want them to fill in additional details about themselves using a model form.
Kori
I'm not sure if that's the correct approach
I'm new to the framework
inchidi
Kori
inchidi
you must specify the user field for each Emplyees object first before alter it with OneToOne then
inchidi
https://pastebin.com/AfXPauWq
you must delete this migration file first and make Employees.user = ForeignKey(User, ...) first instead OneToOne
Kori
Oooh I didn't know that
Thanks
Cause it was still throwing me errors 😂
Kori
Thanks a lot
So should I first delete the model and the migrations and restructure it again?
inchidi
you dont need to delete the model, just make user=ForeignKey(User, on_delete-models.CASCADE) on class Employees
Kori
It's worked
Thank you
N S
Maz
https://pastebin.com/xqhXqh1H
Maz
https://pastebin.com/mFEqzZg8
Maz
how can i list all the next of kin for a particular patient? e.g. a patient with id '2'...i should be able to enter this id in the url and see a list of related kin for the patient
Mirco
Django Bot
>> Links
- How to Structure Django Projects
N S
Is it possible to set default values of a field in the createview or inside the template where the createview form is rendered without using modelforms
inchidi
N S
and how to set it in templates
inchidi
simply {{ context_name }}
N S
fine
Pepeluqui
Hi, Any way to generate an executable of a django application?
Pepeluqui
I have tried with pyinstaller without luck
Pepeluqui
To make it portable to other users
inchidi
you can simply create .bat (windows) or .sh file for that?
Pepeluqui
Yes but I also would like to ofuscate the code
inchidi
but your user could access the db directly instead if they want tho
N S
how to upload csv file to models using modelform
inchidi
add enctype="multipart/form-data" to the <form>. read also
inchidi
Pepeluqui
I have followed those steps
Pepeluqui
Let me give you the exactly screenshot in a while. I am not with the computer now.
Django Bot
>> Links
- Building a todo app using Vue.js and Django as the backend : vuejs
- Django Stripe Tutorial - TestDriven.io
Django Bot
>> Links
- Cross Site Request Forgery protection | Django documentation | Django
- Django Channels Tutorial
- Building Progress Bars for the Web with Django and Celery | Build with Djan
- NewbieMistakes – Django
Pepeluqui
This is the error before creating an executable with pyinstaller
Django Bot
>> Links
- python - Run django application without django.contrib.admin - Stack Overfl
Django Bot
>> Links
- CS50's Web Programming with Python and JavaScript
- Try DJANGO Tutorial Series - YouTube
Karim Norman
I have a questions, how I can create a queryset where the foreignkey is filtered? An example. I have a model where Postcode is a model object and has a one to many relation with suburb with the rel name suburbs.
Now if I create a queryset
postcodes= Postcode.objects.filter(suburbs__name__startswith=SEARCH_TERM)
I get the all the postcodes that includes the suburbs starting with the search term. But the postcodes can include also other suburbs and I would like to construct the queryset to have JUST the suburbs in the serch term. Is there any way to do that?
Code9
Code9
suburbs__name = SEARCH_TERM would work
Karim Norman
but I need the startswith, because the search term can be just few letters
inchidi
what do you mean by "the search term can be just few letters" btw?
Code9
I would like to construct the queryset to have JUST the suburbs in the serch term
Code9
Do you mean you would like to check if the format for the postcode is correct first
Code9
if len(SEARCH_TERM) > 5:
postcodes= Postcode.objects.filter(suburbs__name__startswith=SEARCH_TERM)
else:
postcodes= Postcode.objects.filter(suburbs__name=SEARCH_TERM)
Code9
inchidi
inchidi
suburbs__name = SEARCH_TERM different with suburbs__name_iexact = SEARCH_TERM
Karim Norman
I used startswith