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
Tag: django-models
How to register inherited sub class in admin.py file in django?
Project Name : fusion App Name : admin_lte Python 3.7 Django 2 MySql Question is “I want to register sub model in django admin-panel”,when i write code for model registration in admin.py file that time occurred below error. django.core.exceptions.ImproperlyConfigured: The model Device is abstract, so it cannot be registered with admin. NOTE : I used multiple separated model file. device.py
Chained Selects in Django [Module: django-smart-selects]
I’m trying to use the django-smart-selects Module in order to create dependent dropdown lists. I’ve followed the documentation and defined models in which I used the ‘ChainedForeignKey’ in order to define a link between my companies and my products. models.py Then I have defined a form : forms.py The data is retrieved from my database and I can select a
How to list applied migrations from command line?
I had run makemigrations and after that migrate to apply the migration How to find out models in boards from command line? Answer You’ll need to use some undocumented APIs for this, but here’s one way: After this, loader.disk_migrations will be a dictionary whose keys are (app_name, migration_name) tuples, and whose values are the Migration objects. So iterating loader.disk_migrations.keys() will
Getting an Assertion error in my django application(1.8.4)
I am getting an exception value on running application : (“Creating a ModelSerializer without either the ‘fields’ attribute or the ‘exclude’ attribute has been deprecated since 3.3.0, and is now disallowed. Add an explicit fields = ‘__all__’ to the StockSerializer serializer.”,) Answer As the error message says, the required attribute is fields with an ‘s’, not field.
Prevent DateRangeField overlap in Django model?
Now that Django supports the DateRangeField, is there a ‘Pythonic’ way to prevent records from having overlapping date ranges? Hypothetical use case One hypothetical use case would be a booking system, where you don’t want people to book the same resource at the same time. Hypothetical example code Answer I know that the answer is old, but now you can
Getting TypeError: __init__() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries
I have two classes in my sqlite database, a parent table named Categorie and the child table called Article. I created first the child table class and addes entries. So first I had this: And after I have added parent table, and now my models.py looks like this: So when I run python manage.py makemigrations <my_app_name>, I get this error:
Django: Related model ‘users.UserProfile’ cannot be resolved
I tried running makemigrations and after migrate and I am constantly getting this error: What I was trying to do is Link a UserProfile model to Django’s own User Model: The “Contests” model (as you can see in my installed apps below) uses the User Model as well without any errors. My Installed apps look like this : My migration
Django Admin set extra to 0 when editing
Setting extra = 1 in my model always shows a 1 empty field. It is OK while inserting a new item but I don’t want to show an additional empty field while editing. How can I do this? models.py: admin.py: Answer Override the get_extra method instead of setting a value for extra class member. Returns the number of extra inline
Django rest framework serializing many to many field
How do I serialize a many-to-many field into list of something, and return them through rest framework? In my example below, I try to return the post together with a list of tags associated with it. models.py serializers.py views.py Answer You will need a TagSerializer, whose class Meta has model = Tag. After TagSerializer is created, modify the PostSerializer with