Questions tagged [django-models]

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

0
votes
0answers
10 views

How to populate the Django Model with the data fetched from the external site?

From the external site thru API, I have fetched the dictionary data that I want to save it to the Django Model. I have tried to save the data to the Django Model at the models.py but failed. In ...
0
votes
0answers
4 views

Change field in one model while adding an entry in another model automatically in admin

I have two models in my django webapp. One is Detector which has a detector_id and current_location and the other is LocationTransfer which stores the changes to the location of each detector (one-to-...
0
votes
0answers
17 views

Remove White spaces in Django

I am trying to show a table which gets its information from SQL database using models. I can see the table however, the problem is my database has too many trailing white spaces. I need to strip these ...
0
votes
1answer
23 views

How to perform search in django

i'm having issues searching the articles on a blog post i'm currently working on it keeps giving me errors this is my views.py def search(request): template ='articles/search.html' query = ...
-1
votes
0answers
21 views

Django logic problems

I'm fresh to Django. I have 3 questions/problems regarding logic. I'm using the Django forms and I don't want the other way during this process. Task 1. As soon as the user gets registered an ...
0
votes
0answers
13 views

Outer join django Models . Many to Many relationship

I am unable to join the following tables I tried these things . But i am still unable to to join CartDetail and Products table on the basis of product_id I am using django 2.1.7 ''' Product ...
0
votes
0answers
10 views

Which pattern to use for a model to have different variations of? Generic FK, multi-table, inheritance, others?

I am having trouble deciding how to structure my models for a particular data structure. The models I have would be Posts, Groups, Users. I want the Post model that can be posted from a groups page ...
0
votes
1answer
25 views

Building a ranking system on Django

I have a Django soccer app with following models and I want to make a queryset (or something else) to build a "ranking" table on my template (pass as context): Round (round_number, round_name) Game (...
-1
votes
0answers
14 views

Django - models - number of fields not known in advance

It's not about forms but about models. Right now I have : class Verse(models.Model): code = models.CharField( max_length=10, verbose_name='vers', unique=True) # ex : v01 # ... others fields ...
0
votes
0answers
17 views

Data in table is not updated from django-rest-framework UpdateAPIView?

This is my update api view: class CountlUpdateView(UpdateAPIView): serializer_class = CountSerializers def get_queryset(self, *args, **kwargs): id = self.kwargs.get('pk') ...
0
votes
0answers
19 views

How to dynamically load data into Django template

I am trying to load data dynamically into a django template using a bootstrap modal. What I am doing right now works: def showprofile(full_name): return mentee.objects.filter(full_name="...
0
votes
0answers
24 views

Set query for models that have complex relations in django (Example: LMS)

I have models and betwen them exist complex releations.I want to set query for this situation. This is my files: Models.py class Course(models.Model): category = models.ForeignKey(...
0
votes
0answers
16 views

Google authentication to create User model in django

I want to verify user from google and save user details to my basic User model. By following official tutorial https://developers.google.com/api-client-library/python/auth/web-app I made an ...
0
votes
1answer
14 views

Get Django admin.ModelAdmin to display join of two tables

I have a Django app with the following models.py from django.db import models class Order(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=...
2
votes
1answer
19 views

Sum of related objects across 2 FK to the same table, with conditions

I have two models: class User(Model): ... class Message(Model): sender = ForeignKey(User, CASCADE, 'sent_msgs') receiver = ForeignKey(User, CASCADE, 'rcvd_msgs') ignored = ...
0
votes
2answers
21 views

Retrieve form data

I created checkboxes with form for filter data from my model. JavaScript code add textbox when checkbox is enabled. My problem is that I don't know how to retrieve data from textbox and filter by view ...
0
votes
0answers
31 views

Matching query doesn't exist?

I am making a retweet function and it works quite smooth but I am not able to retweet my own tweets , I am able to retweet other users tweets but not mine . It shows that matching query doesn't exist. ...
0
votes
2answers
29 views

How to display model fuction in Django template

What I am trying to do is to get the data from my model to show up a bootstrap modal. What I am doing right now is trying to pass the function data into the view and through the view I am trying to ...
1
vote
1answer
18 views

How to limit query within Django Admin.TabularInline with large scale data

I'm currently loading 50k records of data using admin.TabularInline, the page doesn't load due to time-out. I'm using Django version 1.9 and upgrade is not an option. I have already tried overriding ...
0
votes
1answer
29 views

how to perform inner join wirth on statment on django 1.11

how to make statement of join on in django 1.11, i want to create this statement : select t1.name ,t2.str, t2.num from table_1 as t1 join table_2 as t2 on t2.product_id = t1.id and t2.section_num = 2;...
0
votes
1answer
31 views

Django taking another users stuff

I am adding sales order to my project and only authenticated users can create sales order with their stuffs like contacts customer, items etc but in the UI it is showing me another users options as ...
0
votes
1answer
32 views

Checkbox enable text input

I have two filters (Choice 1, and Choice 2). I can pick one or both at the same time. One filter is on year of date (datumObjave) and another is on name (naslov). My problem is that those filters are ...
1
vote
0answers
15 views

Can I use trained ML model in django

How to use trained ML model in django and run the trained ML model using user provided values in a form.
0
votes
2answers
33 views

Maintaining multiple instance of the same object in Django models

I am creating a small app in Django where I need to maintain details of training batches of different courses. Each of these batches will have a list of topics to be covered. For e.g, A python course ...
1
vote
1answer
20 views

Django use model manager method after filter()

I'm using Django 2.2 I have a Video model with custom methods defined in the model manager class VideoManager(models.Manager): def completed(self): return self.get_queryset().filter(...
-2
votes
1answer
29 views

How can i forward declare a class argument in python?

When declaring Django models, this problem came across: class Foo(Bar): pass class Bar(): pass NameError: name 'Bar' is not defined How can i forward declare a class argument in python 3....
0
votes
0answers
13 views

Archiving, handeling related deltions

I am always stuck in the following type of situation: Say I have a model/database table Product. The product is produced in a ProductionLine. so the product has a Foreign key to the ProductionLine. ...
0
votes
1answer
13 views

In Django, how can I prevent a “Save with update_fields did not affect any rows.” error?

I'm using Django and Python 3.7. I have this code article = get_article(id) ... article.label = label article.save(update_fields=["label"]) Sometimes I get the following error on my "save" line ... ...
0
votes
1answer
24 views

Function that filter the future posts with datetime.now() - Django

I'm trying to make a function inside a model that don't return the post published in a future. This is the model: from django.db import models from django.utils import timezone import datetime ...
0
votes
2answers
30 views

Can't upload and see image from django models

I am trying to upload images at my model and later on show it at template. Forms.py: class ClanakForma(forms.ModelForm): class Meta: model = Clanak fields ='__all__' Models.py: ...
1
vote
1answer
28 views

How to Render a table in template

Models timetable_choices =( ('Monday','Monday'), ('Tuesday','Tuesday'), ('Wednesday','Wednesday'), ('Thursday','Thursday'), ('Friday','Friday'), ('Saturday','Saturday'), ) ...
0
votes
1answer
30 views

How to do an equivalent of “overlap” keyword of Django 2.2 in Django 1.11?

Suppose I have a model "Books" which has a field named "locations_available". This field stores a list of locations in which a book is available. Now, I have a query_list = ['US', 'Germany', 'Italy']. ...
1
vote
1answer
31 views

Filter - How to implement

I need to implement multi-choice filter in my Django software. I have my model (database): models.py class Autor(models.Model): naziv = models.CharField(max_length=30, null=False, blank=True) ...
1
vote
0answers
23 views

SQL Union All in Django Orm

I am currently working on a project in which I have below-described tables, using below table I want to make a query which will show remaining stock position so I want to make using Union All in ...
0
votes
2answers
29 views

Ensure that there are no more than 3 digits before the decimal point error when submitting a form

I am getting the error "Ensure that there are no more than 3 digits before the decimal point" when I am trying to submit a modal form. How can I fix it? my model: class Product(models.Model): ...
1
vote
1answer
29 views

Download BinaryFiled Data

how to download BinaryField Data/file using template. like we did for FileField. <td><a href={{certificate.bytes.url}} download></a> I past all url.py and view.py file below please ...
0
votes
1answer
29 views

How to fetch data from one model and display it in the form as drop down for storing it in another model in django

i have a 3 models namely category, brand, products. i have to include the category and brand in the products form for displaying it in drop down and selected value should be assigned in the products ...
0
votes
1answer
8 views

Why aren't my Radio Buttons in my django template being able to be selected or displayed?

I have been trying to get radio buttons to display on my Django website for a while now and keep running into issues. I finally found out about manually rendered form fields and have been working ...
1
vote
0answers
42 views

Passing a class variable from Models.py to another .py file for processing

Note: I am a django/python beginner I currently have a User class in models.py that allows a user to upload an image to my app. This is supported by a form and template that allow the upload. This ...
2
votes
1answer
38 views

UNIQUE constraint failed Error when save new obj in django

I have this model: #models.py class Enrollment(models.Model): student = models.ForeignKey(User, on_delete=models.PROTECT) curriculum = models.ForeignKey(Curriculum, on_delete=models.PROTECT) ...
0
votes
1answer
16 views

How do we change Field Names in our existing Users table in django

I am trying to Edit Users Table in Django. I am using Users Table to login or register a users. I have to add a new field name Role in that Table but i can't find any option to edit that existing ...
0
votes
0answers
17 views

Django migrations.AlterField choices's orders are being altered. Can I delete this?

Unfortunately, I'm running into some problems migrating Django migrations files since I have way too many models for, let's say, this extremely specific database; therefore, I have 6 migrations files. ...
0
votes
1answer
36 views

Merge queryset from two databases in Django Rest

I have two routes in my api looking like that : http://mywebsite/websites/website_1/annonces/ http://mywebsite/websites/website_2/annonces/ I need to make an ListAPIView merging these 2 routes but ...
0
votes
0answers
13 views

Category clustering in django models

context: creation of a CMS I am looking for an effective way to represent subject nesting/dependance of articles in a Django model. Right now, Categories are defined as follow: class Category(...
0
votes
2answers
50 views

django - Best way to deal with validation checks in model creation

I am trying to figure out how to use validations when creating an object in django. From my POV, there are 2 approaches: Override the default validate_field method of the DRF serializers. Add field-...
0
votes
1answer
17 views

From User can't query models.Model

When Using query from shell I got : >>> q = User.objects.get(username='TestUser') >>> q.agence Traceback (most recent call last): File "<console>", line 1, in <module>...
0
votes
2answers
25 views

Edit doesn't update database

I am trying to edit some informations saved at my database. So from readAllNew.html I am calling edit button: <!DOCTYPE html> <html> <head> <title></title> </...
1
vote
2answers
18 views

Django Rest Framework - conditionally make serializer's field required or not using other field value

In my DRF project, I have a model: class Item(BaseModel): PRIVATE ='PRIVATE' COMPANY ='COMPANY' ACCOUNT_TYPES = ( (PRIVATE, _('Private')), (COMPANY, _('Company')), ) ...
0
votes
0answers
45 views

How to access data from another model using same foreign key?

I want get college data using general_info foreign key. without making nested serializer of college_set in GeneralInfo serializer. Is there any alternative in django rest framework or is not possible? ...
1
vote
1answer
36 views

getting a number instead of field name when i use want distinct values with its count

I am very new to Django I have table Category which contains category class Category(models.Model): category = models.CharField(max_length=100) def __str__(self): return self....

http://mssss.yulina-kosm.ru