django-models

How to create a unique_for_field slug in Django?

佐手、 提交于 2021-02-06 11:55:30
问题 Django has a unique_for_date property you can set when adding a SlugField to your model. This causes the slug to be unique only for the Date of the field you specify: class Example(models.Model): title = models.CharField() slug = models.SlugField(unique_for_date='publish') publish = models.DateTimeField() What would be the best way to achieve the same kind of functionality for a non-DateTime field like a ForeignKey? Ideally, I want to do something like this: class Example(models.Model): title

migrations are not taking place after pushing my code on heroku…?

送分小仙女□ 提交于 2021-02-05 11:34:09
问题 Well its been 12 hours and i'm still unable to deploy my project properly. I just dont know what is wrong happening. You guys can see throughing error that such models not exist . But i'm trying to make migrations my heroku run python manage.py makemigrations and it throughing me this traceback. My code is working perfectly fine in local but on the server side this is happening. Please help me out. Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage

Django 1.9 loaddata errors

自古美人都是妖i 提交于 2021-02-05 11:12:30
问题 ubuntu 15.10 venv python 3.4 / django 1.9 command: python manage.py loaddata flight_data.json(yaml) errors: json: django.core.serializers.base.DeserializationError: Problem installing fixture '/home/nerdbox2/django_/logbook/flights/fixtures/flight_data.json': 'model' yaml: django.core.serializers.base.DeserializationError: Problem installing fixture '/home/nerdbox2/django_/logbook/flights/fixtures/flight_data.yaml': 'model' After trying several csv->model packages and no luck, I decided to

Django 1.9 loaddata errors

你离开我真会死。 提交于 2021-02-05 11:10:31
问题 ubuntu 15.10 venv python 3.4 / django 1.9 command: python manage.py loaddata flight_data.json(yaml) errors: json: django.core.serializers.base.DeserializationError: Problem installing fixture '/home/nerdbox2/django_/logbook/flights/fixtures/flight_data.json': 'model' yaml: django.core.serializers.base.DeserializationError: Problem installing fixture '/home/nerdbox2/django_/logbook/flights/fixtures/flight_data.yaml': 'model' After trying several csv->model packages and no luck, I decided to

How can i Edit/Change the value of a model field from views.py

我们两清 提交于 2021-02-05 08:40:51
问题 Good-day everyone. I want to know how i can change the value of a model-field through the number of items in a defined sessions list I have already made a profile model (which is OneToOne Field to the user model) with a 'level' field as shown below in my models.py; And in view.py, I have created a session called 'answer_list' which is a list that stores all correct answers provided by the user. models.py class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models

How can i Edit/Change the value of a model field from views.py

倾然丶 夕夏残阳落幕 提交于 2021-02-05 08:39:07
问题 Good-day everyone. I want to know how i can change the value of a model-field through the number of items in a defined sessions list I have already made a profile model (which is OneToOne Field to the user model) with a 'level' field as shown below in my models.py; And in view.py, I have created a session called 'answer_list' which is a list that stores all correct answers provided by the user. models.py class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models

How do I include my def clean_slug function into my views or template so that it will work and show “title alr exist”

送分小仙女□ 提交于 2021-02-05 08:12:41
问题 Hi I have written a def clean(self) function in forms to make sure that if there was previously already a post with the same title, they will return a message saying that the title already exists and hence the form cannot be submitted. Problem now: When I enter a title that already exists and I try to create the post, all data previously input will be removed and I will be redirected to a fresh form. No errors were raised. What I want is for the error to be raised and shown to the user when I

How do I include my def clean_slug function into my views or template so that it will work and show “title alr exist”

半城伤御伤魂 提交于 2021-02-05 08:11:34
问题 Hi I have written a def clean(self) function in forms to make sure that if there was previously already a post with the same title, they will return a message saying that the title already exists and hence the form cannot be submitted. Problem now: When I enter a title that already exists and I try to create the post, all data previously input will be removed and I will be redirected to a fresh form. No errors were raised. What I want is for the error to be raised and shown to the user when I

django.db.migrations.exceptions.NodeNotFoundError: Migration accounts.0001_initial dependencies reference nonexistent parent node

耗尽温柔 提交于 2021-02-04 21:36:15
问题 I'm trying to deploy my project on heroku ,i'm using django 3.1 and i'm unable to do that. I'm getting error due to migrations. Please i humble request you to give some time to this question to resolve this problem. Whenever i run the command heroku run python manage.py migrate ,it gives following traceback. Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "/app/.heroku/python/lib

Django : An established connection was aborted by the software in your host machine

风格不统一 提交于 2021-02-04 21:10:31
问题 I am getting this error when i add a specific line in the post request. views.py class LoginVerify(View): print('login') email ="" pswd = "" username ="" def post(self,request,*args,**kwargs): print("post called") self.email = request.POST['email'] self.pswd = request.POST['pswd'] self.username = User.objects.get(email=self.email).username return HttpResponse("Invalid user") If I add self.username = User.objects.get(email=self.email).username then it is showing the error, otherwise it is