Questions tagged [django-models]

The centerpiece of the Django object-relational mapping scheme is the Model.

0
votes
0answers
5 views

Django-chartit: unable to send data on x-axis in mm-yyyy format

How to send data on x-axis using django-chartit.for e g:I have to show 'Jan-2018' ,'Feb-2018','Mar-2018' and so on, on the x-axis but I am not able to do so. I have used from django.db import models ...
1
vote
1answer
12 views

In Django Unite a Dynamic Amount of QuerySets

In my django-application I have a model with “UnitNodes”, “Persons”, and “PersonUnitRelations”. I wish to select all persons related to a list of units. I think it is most efficent if I can do things ...
0
votes
0answers
4 views

Django Admin Models Creation with InterChanging Drop Down Fields

I am doing a parking app and i plan to add some classes and fields. What i would like to create is to add some Cities e.g Bucharest, NY, Paris and for each of them to have some choices e.g for ...
0
votes
1answer
32 views

Can one model class have a specific relation with another set of model classes django?

This is my models: class company(models.Model): User = models.ForeignKey(User,related_name="Company_Owner",on_delete=models.CASCADE,null=True,blank=True) Name = models.CharField(max_length=50,...
-1
votes
1answer
25 views

Why would model.objects.all() and model.objects.filter().all() give different results?

Hi I was about to clearing my Tables in Django.. When i execute: >> model.objects.all().count() >> 0 but >> model.objects.filter().count() >> 50 What exactly is ...
0
votes
3answers
28 views

Django model method for saving values

I'm wondering is it a good practice to have methods in Django model just for setting and saving values? For example I have a model: class Team(models.Model): name = models.CharField(max_length=50)...
0
votes
0answers
16 views

Django: product model with multiple variations and pricing

Crux of the problem: One product can have multiple variations with different prices. For example: if a Shirt has 2 color choices (black and white) and 2 size choices (Small and Large), there will be ...
0
votes
1answer
27 views

Django AttributeError and query does not exist error

File "C:\Users\NICSI\Desktop\lastnow\mynew\cheque\models.py", line 39, in st r return (self.related.relation.username).title() AttributeError: 'NoneType' object has no attribute 'relation' [28/Sep/...
1
vote
1answer
17 views

Problem with success/redirect URL for ModelForm form_valid() function

I am having a bit of difficulty with overriding the form_valid() method of a CreateView. I have a ModelForm where users can register a new patient. The form is handled by a CreateView. I have ...
0
votes
1answer
24 views

How to store Model methods separately?

I have an AbstractUser model which adds about 20 custom model methods. I want to store these methods properly and idea is to sort it by logic, for example AdminMethods, PaidUserMethods etc. I tried to ...
0
votes
0answers
12 views

ManyToMany field not display in the admin page when add records [duplicate]

I want to create many-to-many relationship with these 2 tables 1.Qa table ------------- |ID | QA | ------------- |1 |qa1 | |2 |qa2 | |3 |qa3 | ------------- 2.Tag table -------------...
0
votes
1answer
15 views

Django forms with two different models

I'm making a questionnaire app, where the question model/table has a variable number of questions, but the response format is uniform e.g. between 1-5. They are contructed like this: class ...
0
votes
1answer
25 views

How to use multiple annotation with filter in Django?

I have use below code for getting result but always get same output for total_deal and total_coupons. I dont know what is happening in this code. total_coupons = Count('coupon', filter=Q(...
0
votes
0answers
16 views

Django 2: unresolved attribute reference 'get_queryset' for class

get_queryset is not work in model manager models.py model manager class ProductManager(models.Model): def featured(self): return self.get_queryset().filter(featured=True) I'm trying to ...
0
votes
1answer
14 views

How to use a string to call a queryset in Django?

I have 2 models which have foreign keys referencing a third model. Its something like this: class Foo(models.Model): ... class Model1(models.Model): foo = models.ForeignKey(Foo, related_name=...
2
votes
0answers
38 views

django python code doesn't return the object I expected

I'm following the example from https://docs.djangoproject.com/en/2.1/topics/db/examples/one_to_one/ Can anyone please help explain why at the lines below doesn't return Restaurant: Ace Hardware the ...
1
vote
0answers
14 views

Not able to save date from datepicker widget into my database

I am new in Django. Basically i have a form in which i have a date_of_birth field and i am take imput into it through a datepicker widget. But i am not able to store it into my database(SQLite). Here'...
0
votes
0answers
7 views

How to call all the subclasses using foreign key in base class in Django?

In my models, I have a base class that has a foreign key to another table. This class is extended by 2 other models. Its something like this: class Foo(models.Model): ... class Base(models.Model)...
0
votes
0answers
13 views

django form not submitted in database

I am trying to submit data using model popup form using django forms.py from django import forms from .models import CollegeMaster from bootstrap_modal_forms.mixins import PopRequestMixin, ...
0
votes
1answer
14 views

Accessing a django model page using reverse_lazy

I have a model named Lal in Django. I have successfully registered it in my admin.py file. Now , what I want is if a particular url is hit then, I should be able to directly redirect using ...
0
votes
0answers
14 views

Add file fields to a django model based on a related model

I have a model where you can define data sources. It's more or less a fixed list but I would like it to be adjustable in the django-admin application, hence its a model. Now I want to create a ...
1
vote
1answer
17 views

When does django calculate properties that aren't stored in the DB

Quick question about performance. Let's say we have some model: class MyModel(models.Model): number = models.IntegerField(default=0) def getComplicatedNumber(self): # do some complex ...
0
votes
0answers
11 views

How to define rating sheet model for an interview?

Pardon the bad drawing. Notations: I - Interview R1,R2,R3,R4 - Rounds RT - Rating Sheet A0, A1, A2, A4 - Aspect(Text Fields) under Rating sheet. Models: class Interview(models.Model): date = ....
0
votes
0answers
16 views

How can I change/monkeypatch model.auth Group __str__ method? [on hold]

I want to monkey patch Django Group model with new __str__ method. I know how to monkeypatch Group's manager but it doesn't work with __str__ method. That's new method that I want to put in Group ...
-1
votes
0answers
13 views

Django redirect to a particular model page directly after login based on user-type [duplicate]

I am a newbie to Django. The project I am working on has a requirement that I am stating below. There will be many users. Each user will belong to a particular group (for this case let us assume that ...
0
votes
0answers
12 views

Django Copy model instance and all inherited related objects with multiple level copying

I want to duplicate a model instance and also duplicate all the child related objects. I am using the following code which i find it in a similar post: def duplicate(obj, value=None, field=None, ...
0
votes
1answer
10 views

UnboundLocalError at /Movies/ local variable 'pichuur' referenced before assignment

ERROR MSG: The web page throws another view when I am trying to create another view and see the contents I have saved in the DB. In models.py: from django.db import models # Create your models ...
0
votes
0answers
12 views

Django redirect after login based on user-type [duplicate]

I am a newbie to Django. The project I am working on has a requirement that I am stating below. There will be many users. Each user will belong to a particular group (for this case let us assume ...
0
votes
0answers
44 views

Django custom user model issue

I am trying to customize user model (name: UserProfile) but when I did makemigrations I got an error: AttributeError: Manager isn't available; 'auth.User' has been swapped for 'accounts.UserProfile' ...
0
votes
1answer
17 views

id auto field error when saved in serializer

I will paste only the necessary code of my issue. I have the following model: class Event(models.Model): id = models.AutoField(primary_key=True) Serializer: class EventSerializer(serializers....
1
vote
1answer
30 views

override model field choices option does not pass validation

in Django 1.11: I have a model field declared like that: a = models.CharField(choices= (('a','a'),('b','b')) In a ModelForm I try to override these choices: class ModelForm(forms.ModelForm): ...
0
votes
2answers
24 views

How to import a .csv table with a foreign key into a django database

This is my first Django project and I am having difficulty loading data from a .csv file into a model with a foreign key. Here are my models: class Artist(models.Model): artistID = models....
0
votes
2answers
19 views

Cannot obtain user by using filter with username and password

I am using the following code email = validated_data["login"] password = validated_data["password"] user_obj = User.objects.filter(Q(email__exact=email) & Q(password__exact=password)) I changed ...
0
votes
1answer
19 views

My django create user and profile signal doesn't work

#from signals.py from django.db.models.signals import post_save from django.dispatch import receiver from .models import User, Profile @receiver(post_save, sender=User) def create_profile(sender, ...
0
votes
0answers
12 views

How to enable copy (mouse click--> copy) for models drop down field in admin change/edit page

As you can see in the picture of admin edit page for a model, i have the the field Team. But i can not copy it using mouse or ctrl+c command. The model is simple: class Device(models.Model): ...
0
votes
2answers
15 views

Dynamic Instance Specific Django Field Creation

I have a situation where a User model can have 'X' number of unique fields that need to be added. These fields need to have queries run on them, so I cant just add a field containing a string of JSON ...
1
vote
1answer
12 views

Django 2.0 Annotate an Annotation Queryset

I have a set of inspectors, each with a number of projects that they work on, and get paid for based on their pay_rate. My goal is to roll up the average pay rate of inspectors based on what company ...
1
vote
1answer
13 views

Possible to have a on_delete=PROTECT on PageChooserBlock?

Let's say that I have an awesome Wagtail project. In this project I would like a Page where I can add unlimited Pages as links, the code would look like this: pages = StreamField([ ('link_page', ...
0
votes
0answers
27 views

how to retrive the multipal models record by a single function in django on the template

****** i have a course class ,i make a index function to retrieve all course in template. then each particular course have its subject i make a function course_content and retrieve each course ...
0
votes
1answer
16 views

how to filter foreign key in django form without passing foreign key value?

I have created two models in my django project AddStudent and Fee Entry as shown below. models.py class AddStudent(models.Model): enrollment_no = models.BigIntegerField(primary_key=True) ...
0
votes
0answers
16 views

Django ModelMultipleChoice validation error

I'm trying to send a dynamic amount of selections of checkboxes on obj.html to the /items function. I'm getting the error "Select a valid choice. 1234 is not one of the available choices." But you'...
0
votes
0answers
38 views

How to pass a variable in Django template?

I have a candidate search view. I want to search for candidates with this view, and then if the view was called from clicking on an edit candidate < a href, i want to find the candidate then ...
-2
votes
1answer
38 views

ORM 'like' query in django python

keywords=Donut working with keyword__name__in=Donut but i need to get result keyword__name__in=Don views.py items=ItemVariation.objects.filter(item__restaurant__id = i['restaurant']['id'],...
0
votes
1answer
21 views

DRF IntegrityError: NOT NULL constraint failed: user_id

I can't figure out how to pass user object to the following serializer: class ReviewSerializer(serializers.ModelSerializer): user = UserSerializer(read_only=True) class Meta: model = ...
2
votes
0answers
19 views

Programmatically delete a Wagtail ListBlock item

I have an abstract class that defines a StreamField for a Wagtail Page: class DownloadGroupItem(models.Model): class Meta: abstract = True downloads = StreamField([ ('items',...
0
votes
1answer
22 views

filter django serializer data

Many time we access data via serializer directory according to relationship defined in models in Django(1.11.10). How can i set a filter like fetch-only is_active=1. class DaasJobsSerializer(...
0
votes
0answers
23 views

Avoid n+1 queries for many-to-many relation to self via other many-to-many relation

I have a model of a PolygonMap, consisting of a number of PolygonTiles. Each PolygonTile has a center point and a number of CornerPoints spanned by Edges. Hence each Edge has two CornerPoints and ...
0
votes
1answer
21 views

In Django-rest-frame work 'NoneType' object has no attribute 'attname'

Here i have using abstract concept but when i try to call product it was throwing Error like 'NoneType' object has no attribute 'attname'. In this models.py Product is the main model and other ...
0
votes
2answers
27 views

Django ORM Queryset class behave different with same filters

This is a simple question. I want to 2 filters at once with Queryset class. Let me explain. from django.db.models import Q import datetime from .models import Asset query_set = Asset....
0
votes
2answers
32 views

How to call a function with context in django CB list view?

This is my view: class viewbloglistview(LoginRequiredMixin,ListView): model = Blog paginate_by = 6 def get_template_names(self): if True: return ['blog/view_blogs....