m2m field widget to add or update data as inline formset

26 views
Skip to first unread message

Suraj

unread,
Jan 28, 2020, 4:41:03 AM1/28/20
to Django users
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
Reply all
Reply to author
Forward
0 new messages