Tuesday, January 28, 2020

m2m field widget to add or update data as inline formset

Hello everyone,

This may be quite simple, but I am unable to find a widget which will function same as m2m widget of django, but will also create new model instance if it doesn't exists.

E.g.
If I had models as:
class Outcome(models.Model):
    outcome
= models.CharField(max_length=255)
    outcome_short_name
= models.CharField(max_length=10, blank=True, null=True)


class Course(models.Model):
    course_title
= models.CharField(
        verbose_name
=COURSE_SINGULAR + " title", max_length=200, unique=True
   
)

    course_outcome
= models.ManyToManyField(
       
Outcome, verbose_name=COURSE_SINGULAR + " outcome", blank=True
   
)

Then I want "Outcomes" shown as below while creating course:

Screenshot from 2020-01-28 15-05-09.png


Now, If the outcomes data added by user already exists, then it should only map them to course. Otherwise it should first store outcomes into database and then map them to course.


Any guidance in right direction will be highly appreciated.


Thanks,

-- 
Suraj

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/555a89e7-4ef7-4849-a9d5-032f7cafdac3%40googlegroups.com.

No comments:

Post a Comment