Django ModelForm has no model class specified, Although model in Meta class is set to a model

Error is “ModelForm has no model class specified.” code code code The error is occurs when I’m trying to create a new user form (user_form = UserForm()). Although in my meta class I set models to the User model imported from django.contrib.auth.models. Error Info Picture Answer I think your spellings in your forms are wrong could you try to correct :Changes Meta() to Meta: then models to model

Django: def save() in

I’m trying to add the save-function inside my, but it seems I’m doing something wrong. The user has to type the first- and last-name. Without him or her entering any more data, another field inside my should be filled with a combination from these fields. Is this even possible? Thanks for all your help. Have a nice weekend! Answer Please don’t. This is redundant data. It turns out that keeping data in sync, even on the same database is more challening than it might look at first sight. Django has furthermore several functions like .update(…) [Django-doc] to

How to fix TemplatesDoesNotExist error even after BASE_DIR has been Joined with templates in

Image 1- Error I notice Exception Value: registration/login.html , I don’t even have that in the templates, instead, i have sign-in.html, I have no idea why it mentioned login.html. Please see my templates folder below as image 3-Templates. I’m trying to fix the above error. My project path looks like Image 2- project path Image 3- Templates The image 2 above shows that my templates folder is located in foodtaskerapp folder In the I have added ‘DIRS’: [os.path.join(BASE_DIR, ‘templates’)], in the TEMPLATES section. I think there is an error because before we can get to templates from BASE_DIR we

How to stop having anonymous user in django

So I have a django project and there is one view(home view) which displays the posts of the followed users and that requires a user to be authenticated, if there is no user loged in, then the code returns a ‘AnonimousUser’ is not iterable error and I will like my code to redirect the anonymous user to the login page if the person is on the home view. After some investigation I realized that this can be done with a custom middleware but I dont know how to do it so currently that middleware just prints if a user is

TypeError ‘Purchase’ object has no attribute ‘__getitem__’ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 months ago. Improve this question def vendor(request,pk): current_shop = get_current_shop(request) instance =get_object_or_404(Vendor.objects.filter(pk=pk,shop=current_shop,is_deleted=False)) Answer purchases is a normal QuerySet that yields model instances when iterated over. All your other queries are values querysets, these yield dictionaries when iterated over. itemgetter will only work on objects that support key lookups, like dictionaries, models do not support this. You need to change all your queries to be the same “type” and use

Django user registration form not showing properly

I am making a Django project where there are two types of users customer and restaurant. Both can register separately. Everything is running fine except that I cannot add CSS class to password field and there are warning showing around password field which I don’t how they are coming. soryy for bad code pasting.Just for clarification class ‘CustomerSignupform’ is parent class. Register User View So I have got similar problem for restaurant registration. Thank You Answer Could you try this. I think somehow it will help you.

JSONField in Django continues to remain empty even after POST request

I have a model with a JSONField in Django. If I issue POST through the browser using Django Rest UI, the data gets entered into the model with no issues. However,when I use Python’s in my application, everything except the JSONField data stores in the model. Here is my model Here is my Serializer Here is my view Here is my request URL What I see after using Answer try data in this format . and remove jsonvalue

Template file not found Django

I am trying to make a home page of a new website via Django. My app name is ‘blog’, home page is home.html I still receive the error template does not exist when I go to I made sure I added ‘blog’ to my templates in and that I added the folder templates in the main directory as well as through blog/templates/blog/home.html myproject/blog/ myproject/blog/ myproject/ myproject/ Do you see anything in my code which causes a problem? I receive the message in blog/ that “Template file ‘blog’ not found” on the line return render(request, ‘blog/home.html’) Answer You are

django migration is not creating all the fields from defined model class into db

Hi i am trying to generate migration but all fields are not getting created into the db. Below is my code. Answer Oh, I find the issue. You are putting comma after defining each field. Remove them and you are good to go!

Get value of related object by list of fields in @property

I have two model like this with following fields: I Also I have this list of fields name: And finally I want to I create this @property: But for related objects this isn’t the correct way and I got this error: ‘Profile’ object has no attribute ‘address.postal_code’ How Can I use this list for get value of field of Profile objects and related object values? Notice: I could solve this problem by using eval function, but because of this and this post, I preferred to throw this solution away. Answer Rather than having Profile nose around in its peers’ internals,