django-models

Django Admin Create Form Inline OneToOne

好久不见. 提交于 2020-04-30 09:07:29
问题 I have the following model: from django.db import models class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) last_password_reset = models.DateTimeField(auto_now_add=True) needs_password_reset = models.BooleanField(default=True) image_url = models.URLField(max_length=500, default=None, null=True, blank=True) I am trying to inline this into the admin. I have the following: from django import forms from django.contrib.auth.models import User from django

Django multiple dropdowns showing model objects

一笑奈何 提交于 2020-04-18 12:38:22
问题 I want to have multiple dropdowns, each showing the available objects from one specific model. So Dropdown 1: Apples Oranges Pears and, Dropdown 2: Apples Oranges Pears etc. The bonus question is to have these dropdowns linked/be dependent so that as the user selects items, these chosen items are removed from the remaining dropdowns. Is this possible? 回答1: It is possible. Import your Model to the view-File. Example: def editUser(request): users = "YourModel".objects.all() if request.method=

Django multiple dropdowns showing model objects

余生长醉 提交于 2020-04-18 12:37:02
问题 I want to have multiple dropdowns, each showing the available objects from one specific model. So Dropdown 1: Apples Oranges Pears and, Dropdown 2: Apples Oranges Pears etc. The bonus question is to have these dropdowns linked/be dependent so that as the user selects items, these chosen items are removed from the remaining dropdowns. Is this possible? 回答1: It is possible. Import your Model to the view-File. Example: def editUser(request): users = "YourModel".objects.all() if request.method=

Django don't generate primary_key

僤鯓⒐⒋嵵緔 提交于 2020-04-18 05:45:27
问题 I write the migration manually to quickly add to the new environment. When I try to create a new object of the Operator model I get an error about an empty id. I tried to set managed = False in meta and fake Operator model but none of this brought results. What's wrong with my code? My model: class Operator(models.Model): id = models.IntegerField(primary_key=True) name = models.CharField(max_length=256) class Meta: db_table = '"mts_market"."operator"' managed = False def __str__(self): return

One To Many and models

时光毁灭记忆、已成空白 提交于 2020-04-18 05:44:09
问题 i am trying to build my first project, a CRM website to handle orders and inventory. and i got stuck, i was able to link orders to customer. but when i try to build order that contain multi items. for some reason i didn't find a way to do it. hope you can assist me. so I have User>>Order>>Multi Items. questions: 1) does the best practice here is just use ForeignKey ? this my model's code: from django.db import models class Customer(models.Model): name = models.CharField(max_length=200, null

Django - Trying to create a GIF from uploaded video

余生长醉 提交于 2020-04-18 03:49:27
问题 I have a model class representing a video file. It has also a GIF field. I want to create also a GIF file of each video file. Before saving, I fill the gif field with the content of video field in the save() method like this: class Video(models.Model): created = models.DateTimeField(auto_now_add=True) text = models.CharField(max_length=100, blank=True) image = models.ImageField(upload_to='Images/',blank=True) video = models.FileField(upload_to='Videos/',blank=True) gif = models.FileField

Django - Trying to create a GIF from uploaded video

只愿长相守 提交于 2020-04-18 03:49:23
问题 I have a model class representing a video file. It has also a GIF field. I want to create also a GIF file of each video file. Before saving, I fill the gif field with the content of video field in the save() method like this: class Video(models.Model): created = models.DateTimeField(auto_now_add=True) text = models.CharField(max_length=100, blank=True) image = models.ImageField(upload_to='Images/',blank=True) video = models.FileField(upload_to='Videos/',blank=True) gif = models.FileField

How to declare a auto-incrementing alphanumerical id field with predefined aplphabetic part (Django python)

早过忘川 提交于 2020-04-17 22:51:28
问题 I am developing an app in Django. I want to insert in my model an auto-incrementing alphanumerical ID field, having, by default, a fixed alphabetical part and an auto-incrementing numerical part. But I also want the availability to change, from admin section, this id to another alphanumerical one, with a different alphanumerical and numerical part. Please note: I don't want to overwrite the django default id field, I just want to include in my model a field that gets as default value an auto

django forms exclude values from choicefield that are already into database

↘锁芯ラ 提交于 2020-04-16 02:37:25
问题 I want to exclude those options from the ChoiceField in the forms that has been already selected and are into the database. Below is the Code. models.py SEMESTER_CHOICES = ( ("1", "1"), ("2", "2"), ("3", "3"), ("4", "4"), ("5", "5"), ("6", "6"), ("7", "7"), ("8", "8"), ) class Publish(models.Model): dates = models.CharField(max_length=255, choices = SEMESTER_CHOICES) def __str__(self): return self.dates form.py SEMESTER_CHOICES = ( ("1", "1"), ("2", "2"), ("3", "3"), ("4", "4"), ("5", "5"), (

django forms exclude values from choicefield that are already into database

懵懂的女人 提交于 2020-04-16 02:36:54
问题 I want to exclude those options from the ChoiceField in the forms that has been already selected and are into the database. Below is the Code. models.py SEMESTER_CHOICES = ( ("1", "1"), ("2", "2"), ("3", "3"), ("4", "4"), ("5", "5"), ("6", "6"), ("7", "7"), ("8", "8"), ) class Publish(models.Model): dates = models.CharField(max_length=255, choices = SEMESTER_CHOICES) def __str__(self): return self.dates form.py SEMESTER_CHOICES = ( ("1", "1"), ("2", "2"), ("3", "3"), ("4", "4"), ("5", "5"), (