Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7437439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:23:59+00:00 2026-05-29T10:23:59+00:00

Consider I have defined the following models: class Tag(models.Model): name = models.CharField(max_length=20) class Entry(models.Model):

  • 0

Consider I have defined the following models:

class Tag(models.Model):
  name = models.CharField(max_length=20)

class Entry(models.Model):
  title = models.CharField(max_length=100)
  date = models.DateField()
  tags = models.ManyToManyField(Tag)

and the following model form:

class EntryForm(forms.ModelForm):
  tags =  CharField(max_length=100, label='Tags', required=False)
  class Meta:
    model = Entry

Basically I have an entry with tags. The tags are not necessarily already created. I need to receive a filled entry form and save it with tags.

I can do that easily if I don’t have the ManyToMany relation in the Entry. But with it I first need to save the tags, then add the saved tags to the entry and then save the entry. Which means I have to override the EntryForm’s save() method.

I saw this question already, but it looks different. In my case I need to save only the tags, and the rest should be able use ModelForm’s default save().

I presented a simplified example. In real one I have much more fields in the Entry.
What is your recommendation for writing EntryForm’s save() method in a django way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:24:01+00:00Added an answer on May 29, 2026 at 10:24 am

    The best and correct option here would be to add the clean_tags method to the form, not to override the save() in the model.

    def clean_tags(self):
        tags = self.cleaned_data.get('tags', None)
    
        clean_tags = []
    
    
        tags = [tag.strip() for tag in tags.split(',') if tags]
    
        for tag in tags:
            t, created = Tag.objects.get_or_create(title=tag)
            t.count = F('count') + 1
            t.user.add(self.cleaned_data['user'])
            t.save()
            clean_tags.append(t)
    
        return clean_tags
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider a database(MSSQL 2005) that consists of 100+ tables which have primary keys defined
Consider the following Spring Service class. The spring scope defined is Singleton. The two
Consider the following, I have a Job class that has inputs and one output.
consider the following code: class MyClass(object): def __init__(self): self.data_a = np.array(range(100)) self.data_b = np.array(range(100,200))
I have the following issue. Consider 2 models with attributes: Place - lat -
Consider the following: I have two tables (Customers and Cases) defined as follows: **Customers**
Consider the following. You have a class that you want to serialize with XmlSerializer
Consider I have the following text in a UILabel (a long line of dynamic
Consider I have the following interface: public interface A { public void b(); }
Consider I have an anchor which looks like this <div class=res> <a href=~/Resumes/Resumes1271354404687.docx> ~/Resumes/Resumes1271354404687.docx

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.