Questions tagged [django-models]

For questions concerning use of the model class from the web framework Django.

0
votes
0answers
5 views

How can I reidirect my create view to a url id whose id is same as create view id django

I am trying to make a createview which will create users information and then redirect them to profile page with that information fullfiled but the problem is after submitting a form it redirects ...
0
votes
1answer
12 views

Django Python Show functions in html

Let's imagine that i have this in the models: def show(): print("Hello bro") And i want to show that function on my html page, how woulded it?
0
votes
0answers
16 views

Get multiple models in single QuerySet ordered by timestamp

I'm working on a table consisting of all events performed on a user despite that these events are represented by 4 different models. The models are: WebhookSubscription WebhookEvent TokenRefresh ...
0
votes
0answers
18 views

Pass QuerySet object id to model to get self

I am trying to trigger a method in my models to run by hitting a url.When it hits it returns and error saying "unsupported operand type(s) for -: 'datetime.datetime' and 'NoneType'". views.py from ...
1
vote
2answers
21 views

is there a way to override model methods in django?

I have a model like this: class Car(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4) create_date = models.DateTimeField('date added', auto_now_add=True) ...
2
votes
1answer
18 views

AttributeError: 'tuple' object has no attribute 'client'

im trying to access a cached_property from a model and its returning 'tuple' object has no attribute 'client' this is the model that has the cached_property class Creds(models.Model): tenant ...
0
votes
1answer
14 views

importing models inside django application

I have made an app inside my django application. I'm trying to create a file(testabc.py) in the same directory as views.py and I want to import models in that file. The name of model is "Example" ...
1
vote
2answers
19 views

Django Registering two different types of users with different fields

I want to create two users: patient and doctor. Both users will share some of the standard fields like first_name, last_name, etc. However, they should have different fields. Only the doctor, for ...
0
votes
0answers
6 views

Django models and unique fk

Let's assume I have model A and model B defined as such: class model_A(models.Model): headline = models.CharField('Referral headline') def __str__(self): return self.headline ...
0
votes
1answer
19 views

Get data objects that do not have onetoOne relationship

My problem is that i need to get the unmatched data objects from both Table1 & Table2. class Table1(models.Model): client_id = models.IntegerField(primary_key=True) spend = models....
0
votes
0answers
16 views

Display image in Django admin - Many to many inline admin view

I have the following models: class AModel(BaseModel): a_id = models.AutoField(primary_key=True) name = models.CharField(max_length=200) a_images = models.ManyToManyField(BModel) class ...
1
vote
1answer
31 views

Django ORM: create ranking based on related model count

I have 2 models in my database: Movie and Comment (it has a foreign key pointing to Movie). from django.db import models class Movie(models.Model): title = models.CharField(max_length=120, ...
0
votes
2answers
29 views

Django:How to perform a query with settings.AUTH_USER_MODEL?

This is my model: class Company(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL,related_name="Company_Owner",on_delete=models.CASCADE,null=True,blank=True) name = ...
-1
votes
1answer
31 views

Django list data from dfiferent models in List View with correct ordering

Heys guys.. I am making a Django project which is a simple clone of Twitter.. Got the idea from Justin Mitchell's Udemy course.. So i implemented a Tweet model and a Retweet model which has ...
0
votes
2answers
16 views

Can I retrieve the HTML element in a django form?

I have a ModelForm, MyForm. Help me write a method that returns html elements for each field present in the form. class MyForm(forms.ModelForm): priority = forms.ChoiceField( widget=forms....
1
vote
1answer
14 views

Custom Manager not always adding calculated field for many-to-one relationship

I am using Django 2.1 for a project. One of my Models (called Event in the example below) has a many-to-one relationship to another Model (Thing in the example below). The first model should have what ...
0
votes
0answers
24 views

Rebuild Model file from migrations

I had a complete models.py file. Unfortunately, some of my model class has been deleted. But I did migration before this incident happened. My Question is, Is it possible to rebuild the models....
1
vote
1answer
45 views

Django How to add to a foreign key field

I want to design a model for the currrent user to see all the people he referred. I create another model to keep track of all the referral relation between users, such as 'stephen -> jack', 'stephen ->...
0
votes
0answers
23 views

Is serialization the best way to implement a save game feature in a Django game?

I'm writing a simulation game in Django and was wondering what the best way to implement a save game feature would be. I want each user to be able to create, save, and load multiple games independent ...
1
vote
1answer
28 views

How to get django admin change form to pre-select choice field?

I have a model field with choices, as defined here: class Pack(models.Model): SIZE_10x20 = Decimal(200.000) SIZE_10x10 = Decimal(100.000) SIZE_5x10 = Decimal(50.000) ...
0
votes
1answer
22 views

Disable Django model admin buttons (save, delete, etc.)

I would like to disable all buttons that they are present into the submit-row (save, save and edits, delete, etc...) after the click on one of they. I started to try to override the change_form for ...
1
vote
1answer
30 views

Django two ForeignKey from same model

In Pegawai model, I need two ForeignKeys to: Jabatan model unit_kerja field of Jabatan model How to apply these for my Pegawai model? Only the first one worked. Here is my models.py: from django....
0
votes
1answer
18 views

Django Custom User Model - Form Tuple Problems

I'm creating a Custom User Model, based on AbstractUser, which has several extra fields added. I've read through the documentation and assorted examples, but I'm having a couple of frustrating (and ...
0
votes
1answer
19 views

toggle_paused() missing 1 required positional argument: 'self' when view runs models method

I am getting the error TypeError: toggle_paused() missing 1 required positional argument: 'self' when I trigger ToggleView(). I am still pretty new to Django and im not sure how to resolve the issue. ...
2
votes
2answers
27 views

Error in python django when trying to save a user manually

I am experimenting some error when i try to create a new user manually in django This is my code: from django.contrib.auth.models import User newuser = User() newuser.username = request.data['...
0
votes
0answers
9 views

CHECKBOXES instead radio buttons at DJANGO ADMIN?

If you are looking for a way to put radio buttons in Django using MODELS you only need do something like this (e.g): in models.py class MonitoringPointsClass( models.Model ): ...
0
votes
0answers
20 views

Django Model Admin - Traffic Light Alert

I have a series of models all the same as this one: class Documents(models.Model): id = models.AutoField(primary_key=True) paper = models.ForeignKey( 'Paper', models.DO_NOTHING, blank=...
1
vote
1answer
32 views

Django 2.1.7, IntegrityError, FOREIGN KEY constraint failed

I have a problem with ForeignKey relation between User and Post models. Or rather, when creating the ForeignKey for the Custom User Model, an error appears: Traceback: File "C:\Users\jack_\....
0
votes
1answer
30 views

How to use Django models outside of Django?

Following this guide, I am able to use models outside of Django with the following file structure by calling python main.py. ├── data │ ├── __init__.py │ ├── migrations │ │ └── __init__.py │ ...
0
votes
0answers
13 views

Developing a queryset using a “through” foreign key

I'm looking to build a queryset of UserCarts that have UserCartItems that are related to a particular UserService: For example, if a UserService is "Painting", I'd like to get a queryset of all ...
0
votes
1answer
13 views

Referencing model attributes within form

I am hoping to edit multiple models at the same time on a singe page. Rather than using formsets, I got this to work with an array of forms that I loop through in the template in the view: {% extends ...
0
votes
2answers
25 views

Django model design advice

I am currently learning Django, specifically DRF to make an API that will be consumed by a web app client. The app is for a teacher who gives extracurricular classes in Mathematics and Science. My ...
1
vote
1answer
20 views

Django - model mixin doesn't work as expected

In PipedriveSync model I use GenericForeignKey so any model can have PipedriveSync object related. class PipedriveSync(TimeStampedModel): ... content_type = models.ForeignKey(ContentType, ...
3
votes
0answers
59 views

Django model constraint for related objects

I have the following code for models: class Tag(models.Model): user = models.ForeignKey('auth.User', on_delete=models.CASCADE) class Activity(models.Model): user = models.ForeignKey('auth....
0
votes
1answer
13 views

In Django when extending AbstractUser, how do you reorder admin fields?

In a Django app I have a class that extends AbstractUser: class CustomUser(AbstractUser): uid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) ...more fields that are ...
0
votes
2answers
20 views

Get m2m field (with through model) list in django

I'm using Django 2.0.7. I want to get all the fields of a model. I can get all the normal fields in: model._meta.fields And I can get m2m fields in: model._meta.local_many_to_many However, if the ...
-3
votes
0answers
18 views

I'm creating a webhook(Http callbacks). I have to convert my code using Django rest framework from Django standard code

This is code which I'm using in Django standard code Tasks.py class ProcessMessages(PeriodicTask): run_every = crontab() # this will run once a minute def run(self, **kwargs): ...
0
votes
2answers
24 views

How to do in operation in django

class ModelA(models.Model): f = models.CharField(max_length=50) class ModelB(models.Model): a = ForeignKey(ModelA) b = models.CharField(max_length=50) I want to get f in model A and I ...
0
votes
1answer
33 views

How to fetch all distinct objects of a parent ordered by some field in the child in django?

I have two Django models named, Categories and Item. A Category can have many Items The model Items has a property is_available which can be True or False. class Categories(models.Model): name = ...
0
votes
1answer
24 views

Django how to implement a one-to-many self-dependent foreign key

I am implementing a User referral system, which existing users can refer other people to register an account with the link they provided. After the new user registers, the new user will be stored to ...
0
votes
1answer
57 views

Django 2.1 — Display model verbose_name from meta in ListView

First section of code works fine; it is for reference. #Basic Model class MyTestModel(models.Model): record = models.CharField(max_length=100) def __str__(self): return self.record ...
0
votes
2answers
30 views

Django - Retrieving fields in another model via mutiple foreignKey relationships

The following sample database stores posts of news and relevant information for each piece of news. I'm interested in retrieving the topics associated with each news. The problem is, they are stored ...
1
vote
1answer
17 views

Django Mixin method that affects composite class

Say I have the following simple classes: class NumberMixin(models.Model): number = models.IntegerField() class RaceCar(models.Model, FancyMixin, ScaryMixin, NumberMixin): def common_logic(): ...
0
votes
1answer
12 views

Django foreign-key and one-to-one access best practice

Say I have the following Models: class User(models.Model): name = models.CharField(max_length=255) ... class Knapsack(models.Model): user = models.OneToOneField( User, ...
2
votes
3answers
60 views

How to store a complex number in Django model

I need to store a complex number in a Django model. For those who forget, that simply means Z=R+jX where R and X are real numbers representing the real and imaginary components of the complex. There ...
0
votes
1answer
18 views

How to save array data in django?

How to save array data in django? I have an array and need to save it. fields= { "description":"Medida", "name": "medida", "tipo": "tipo" } ...
0
votes
1answer
23 views

“no migration to apply” message where there is some migrations to be applied

I have added a new field called "city" for my custom user model. I will run makemigrations and it create new file in migration folder: migrations.AddField( model_name='customuser', name='city'...
0
votes
1answer
42 views

Django serializer, nested relation and get_or_create

I've been bugging on this issue for some time now. I have two models : Acquisitions and RawDatas. Each RawData have one Acquisition, but many RawDatas can have the same Acquisition. I want to create ...
0
votes
0answers
29 views

Proper way to Update model instance?

On my Django project, I have a form on my my_account_edit.html page and the values of this form where they are displayed are on my my_account.html which I created. I need this form to update the ...
0
votes
0answers
18 views

Adding two separate model fields to calculate for the average

I have two models: class BsoQMS_QA(models.Model): id = models.IntegerField(db_column='ID',primary_key=True) audit = models.CharField(db_column='Audit', max_length=50, blank=True, ...

http://mssss.yulina-kosm.ru