Category : django-models

Hi I am writing a custom user model on django and i have username field along with email field when i set USERNAME_FIELD = ‘username’ i get this error raise FieldDoesNotExist("%s has no field named ‘%s’" % (self.object_name, field_name)) django.core.exceptions.FieldDoesNotExist: User has no field named ‘username’ when i checked the migrations for the model i ..

Read more

So basically I want to be able to prefill a Charfield form field with a certain value in the init method. Here is my form: class UpdateForm(forms.ModelForm): #_____________________________________________________________ def __init__(self, *args, **kwargs): super(UpdateForm, self).__init__(*args, **kwargs) self.fields[‘form_field’].initial = "How are you doing?" self.fields[‘form_field’].widget = self.fields[‘form_field’].hidden_widget() #_____________________________________________________________ class Meta: model = form_model fields = ( ‘form_field’, ) ..

Read more

I’m trying to write a custom method to ovveride the default viewing of a field in ModelAdmin, a described here: https://docs.djangoproject.com/en/3.2/ref/contrib/admin/ So this should work: @admin.register(Contract) class ContractDataAdmin(admin.ModelAdmin): list_display = ("name", "status", "date_end") list_filter = (‘name’,’status’, "date_end", "headquarters_access_list") fields = ("name", "status", "date_start", "date_end", "manager_list", "buyer", "get_document_list_field", "headquarters_access_list") @admin.display(empty_value=’???’) def get_document_list_field(self, obj): return "n".join([c.name for ..

Read more

I am making an Auction website using Django. When is use Migrate command it gives an error "ValueError: Field ‘bid’ expected a number but got " ". The code of the models.py file is: from django.contrib.auth.models import AbstractUser from django.db import models from django.db.models.base import Model from django.db.models.deletion import CASCADE from django.db.models.fields import CharField from ..

Read more