Answer the question
In order to leave comments, you need to log in
How to set value in label for ForeignKey in ModelForm by taking values from specific column of child model?
I have 3 models:
class Cats(models.Model):
id = AutoField(primary_key=True)
name = CharField(max_length=150)
LOC_CHOICES = [('nav', 'navigation panel'), ('main', 'mainpage'), ('footer', 'Footer')]
location = CharField(max_length=150, choices=LOC_CHOICES, null=True, blank=True)
objects = models.Manager()
class Marks(models.Model):
id = AutoField(primary_key=True)
name = CharField(max_length=150)
objects = models.Manager()
class Items(models.Model):
id = AutoField(primary_key=True)
name = CharField(max_length=150)
marks = ForeignKey(Marks, on_delete=models.DO_NOTHING)
category = ForeignKey(Cats, on_delete=models.DO_NOTHING)
price = DecimalField(max_digits=7, decimal_places=2)
previous_price = DecimalField(max_digits=7, decimal_places=2)
article_number = CharField(max_length=150)
description = TextField()
picture = CharField(max_length=500)
objects = models.Manager()
class ItemsForm(ModelForm):
class Meta:
model = Items
fields = ['name', 'marks', 'category', 'picture', 'article_number', 'price', 'previous_price']
labels = {'marks': <тут надо что-то написать>, category: <тут надо что-то написать>
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question