django-model-field

Unique together between field and model connected by ForeignKey django

Unique together between field and model connected by ForeignKey django Question: I have two models. class Post(models.Model): title = models.CharField(max_length=150) class Attachment(models.Model): type = models.CharField(choices=AttachmentChoices.get_choices(), max_length=15) link = models.URLField() post = models.ForeignKey(‘Post’, on_delete=models.PROTECT, related_name=’attachments’) I want to do something like this in meta class of Post model class Meta: unique_together = [(‘title’, ‘attachments’)] but it …

Total answers: 1

How to set placeholder for django integerfield

How to set placeholder for django integerfield Question: I have a model form: class CaseForm(ModelForm): class Meta: model = Case fields = ["sex", "age"] With corresponding model: class Case(TimeStampedModel): id = models.UUIDField( primary_key=True, unique=True, default=uuid.uuid4, editable=False ) user = models.ForeignKey( get_user_model(), blank=False, null=True, on_delete=models.SET_NULL) age = models.IntegerField("Age") SEX_CHOICES = [ ("male", "Male"), ("female", "Female"), (”, …

Total answers: 1

How to create combobox with django model?

How to create combobox with django model? Question: i want to create something like a combo box with django model, but i don’t find any field type to do that. something like this: enter image description here Asked By: Bassam Nazemi || Source Answers: Simply you can do this in models.py: class Student(models.Model): select_gender = …

Total answers: 1