I’m trying to filter ListView based on post method from search bar in my basetemplate. So making it works like: I have done this, but it wont work. Could you please tell me what I’m doing wrong? views.py in my user app urls.py in my blog app search form in html rendered html with user names Answer override get_context_data method
Tag: django
How to show more objects in my html with django (queries)
I want to show more queries within my html page but it only shows a single object. I do not know how to add more This is in mysql, html, django1.11 and python 2.7.15 views.py i need add object mapa and competencias. The object alumno i dont have problem Answer User filter instead of get. Because, get returns a single
Accessing property of model instance from list and add them together?
Say I have a model: Say I have a function: I want to use a for loop to add together the integers in the ‘property’ of the model instance and then output the sum into one of my templates? I have tried the add filter but the problem is the amount of instances it will be adding together are dynamic
Django throws ValueError: save() prohibited to prevent data loss due to unsaved related object save method
I am trying to create some objects of model ABC in from save method of XYZ model, when a XYZ models object is created. See the below code for reference : And here are the error lines : Answer You’re going to want to call super.save() on your MatchDetail before you created your ContestDetail object, not after, as you have
simple comment code won’t collaborate with notification app
my code for comment works fine but as soon as I add notification feature it doesn’t work, while notification kinda works. I’m using django-notification-hq 3rd party app. from here: https://github.com/django-notifications/django-notifications here’s my code views.py urls.py I added this single line, My new model Answer You are overwriting the save-method on the model, you need to pass the arguments to super()
Object of type datetime is not JSON serializable error
I have some issues with using a DateTime value in python. When I use session_start in the following code, I get an Object of type datetime is not JSON serializable error views.py model.py traceback I retrieve the value from a database view which is filled by other tables where the user fills in their data. Could someone help me with
How do I access a model’s nested one-to-many relations?
I have three models as shown below: A restaurant has many menu categories, which has many menu items. Is this the right way to lay out these relationships? What’s the most efficient way to get ALL the menu items for a given restaurant? I’m hoping there’s a more effective way than to loop across all menu categories for a given
Django stops with “generator raised StopIteration” when html form allows for file upload
My setup is Windows 10, Python 3.7, Apache 2.4/mod_wsgi. When I add this enctype=”multipart/form-data” in my form (just by adding this attribute, only — no files are attached to the form) I get this error when submitting: My Django code is this: And this is full traceback: Any ideas what is going wrong? PS: Same django application worked fine in
Django WhiteNoise configuration is incompatible with WhiteNoise v4.0
I am trying to deploy my Django webapp on Heroku. I have been facing this same error everytime I try to deploy. ImportError: Your WhiteNoise configuration is incompatible with WhiteNoise v4.0 This can be fixed by following the upgrade instructions at: http://whitenoise.evans.io/en/stable/changelog.html#v4-0 ! Error while running ‘$ python manage.py collectstatic –noinput’. See traceback above for details. You may need to
Are there disadvantages of using __slots__?
I’m using Python 3.7 and Django. I was reading about __slots__ . Evidently, __slots__ can be used to optimize memory allocation for a large number of those objects by listing all the object properties ahead of time. My perhaps obvious question is why wouldn’t we want to do this for all objects? Are there disadvantages for using __slots__? Answer Fluent