django-models

python ForeignKey relation with user shows this error NOT NULL constraint failed: music_song.performer_id

北战南征 提交于 2021-01-29 15:45:15
问题 Fellow programmers, I am getting a error NOT NULL constraint failed: music_song.performer_id I want the performer field to be the user who is creating the song but its not happening I have tried a lot can you guys please help me out with it models.py class Song(models.Model): name = models.CharField(_("Name"), max_length=50) song = models.FileField(_("Song"), upload_to=None, max_length=100) song_image = models.ImageField(upload_to=None, height_field=None, width_field=None,max_length=100)

Recursive relationship in Django: get all the interrelated records from each record

戏子无情 提交于 2021-01-29 15:13:44
问题 I have this model for a tune: class MsTune(models.Model): name = models.CharField(max_length=255) ms = models.ForeignKey(Manuscript, on_delete=models.CASCADE, related_name="mstunes") concordances = models.ManyToManyField("self", blank=True) I have many manuscripts (ms), and the same tune might appear in more than one manuscript. What I want to do, with that concordances field, is link all the similar tunes. This works, in part. The Django administration back-end allows me to select many tunes

Database messaging for multiple model types - user, group, global

橙三吉。 提交于 2021-01-29 15:04:14
问题 I want to implement an alert messaging system, in a website, that will show a message to either multiple users , multiple groups (different DB representation), or globally to all users. What would a good database relationship for this behavior look like? 回答1: This is where I would start based on the information you've given... A table for the alert messages to be sent out... alerts id unsigned int(P) message text +----+---------------------+ | id | message | +----+---------------------+ | 1 |

django_select2 - limit the returned text to a specific field in module

狂风中的少年 提交于 2021-01-29 14:39:09
问题 I am using django_select2 in my application. I would like to search and display only according to one field of a model. models.py: class Venue(models.Model): venue_name = models.CharField(max_length=50) venue_city = models.CharField(max_length=50) venue_country = models.CharField(max_length=50) def __str__(self): return f"{self.venue_name}, {self.venue_city}, {self.venue_country}" forms.py: from django import forms from .models import from django_select2 import forms as s2forms class

How to display Foreign key Data in Django view page?

て烟熏妆下的殇ゞ 提交于 2021-01-29 14:01:33
问题 i have relation between Project and ProjectFloorPlan , and i want to display ProjectFloorPlan data in my template. Please let me know how i can display the ForeignKey data in my template. Here is my models.py file... class Project(models.Model): name=models.CharField(max_length=225) slug=models.SlugField(null=True, unique=True) def __str__(self): return self.name class ProjectFloorPlan(models.Model): project=models.ForeignKey('Project', related_name='projectfloorplan', on_delete=models

Django ORM: add parent class and access its class variable from children

吃可爱长大的小学妹 提交于 2021-01-29 13:33:02
问题 I am working on a restaurant app (and new to Django/Python). I want to have a parent class Dish that will contain some counter or ID that increments for every instance of a child class of Dish . The instances are dishes like Pizza, Pasta, etc with different characteristics. I've tried making Dish abstract and non-abstract, but come across different issues each time. This is my Dish class (to make it abstract I tried InheritanceManager(), but ran into complications there that led me to think

Setting Academic or Financial Years in Django

て烟熏妆下的殇ゞ 提交于 2021-01-29 11:36:08
问题 This may seem rather insignificant, but how do you set a financial or academic year, say 2018/19 or 2017/2018 in a Django model and reference the current financial year for querying, in this case 2019/20 回答1: consider using a custom queryset class CustomQuerySet(models.QuerySet): def current_financial_year(self): return self.filter(datefield__gte=current_finyear_start, datefield__lte=current_finyear_end) then make a manager out of it CustomManager = models.Manager.from_queryset(CustomQueryset

How to access tables from a different schema in oracle 11g using django?

戏子无情 提交于 2021-01-29 09:46:36
问题 I have a user named mi_abc in oracle 11g. The user do not have any table in the database but has access to all the tables in another schema sch_abc. When I run a normal select query from sqldeveloper on the sch_abc schema from mi_abc, it works perfectly fine, but when I use django, I am always getting the error:- django.db.utils.DatabaseError: ORA-00942: table or view does not exist I tried to set the db_table = sch_abc.tableName and also set db_table = tableName but both gives me the same

Django Error: ValueError at /new_bid/1 Cannot assign “1”: “Bid.listingid” must be a “Listings” instance

放肆的年华 提交于 2021-01-29 09:33:16
问题 I am getting the error: ValueError at /new_bid/1 Cannot assign "1": "Bid.listingid" must be a "Listings" instance." I am still learning about Foreign Keys so I may have used it wrong? I'm also using 'listingid' in both the models 'Listings' and 'Bid.' I'm wondering if this is part of the issue, but it makes sense to have both to me. I am just learning about how 'self' works also, so I think part of the problem is in the Listings model at the very bottom: In the Listings model if I do: return

How to create multiple images upload in Django CreateView?

痞子三分冷 提交于 2021-01-29 09:21:04
问题 I have a django project and I created a post operation in this project, so the user will be able to share multiple picture posts. But I have a problem. I can't write multiple image upload function. I looked at a lot of content, but it doesn't work. Either it reports a problem or contex is not sent to the html page I wanted. Please help me. The multi picture function I want should be under CreateView and should be placed in the same templet as it. Also, there should be 4 Image upload buttons,