Django: CSS class does not show for ModelForm that extends another ModelForm
By : Ujala
Date : March 29 2020, 07:55 AM
|
How to set User-based form field choices in a django ModelForm (with django-allauth)
By : siddhu
Date : March 29 2020, 07:55 AM
|
Django - MultiChoiceField to_field_name and selected
By : Bilel Kharrati
Date : March 29 2020, 07:55 AM
hope this fix your issue Well, I managed to achieve what I wanted. As suggested by @Alasdair, I created an intermediary model. code :
class Model1(models.Model):
name = models.Charfield(...)
muscles = models.ManyToManyField(Model2, blank=True, null=True,)
class Model2(models.Model):
name = models.CharField(...)
field1 = models.CharField(...)
class Model1Model2(models.Model):
model1 = models.ForeignKey(Model1)
model2 = models.ForeignKey(Model2)
class MyForm(ModelForm):
muscles = forms.ModelMultipleChoiceField(
queryset=None,
to_field_name="field1", required=False,)
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields['muscles'].queryset = Model2.objects.all()
|
Django ModelForm fails to save "many to many" records using ModelForm and save_m2m
By : Hai Kara
Date : March 29 2020, 07:55 AM
|
How can I apply filter to Django modelform and return form to view in Django?
By : OscarES
Date : March 29 2020, 07:55 AM
|