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 6760051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:01:21+00:00 2026-05-26T14:01:21+00:00

In [1]: from editor.models import * In [4]: from subscriptions.models import * In [5]:

  • 0
In [1]: from editor.models import *
In [4]: from subscriptions.models import *
In [5]: template = StockTemplate.objects.create(name='Template 1')
In [6]: template
Out[6]: <StockTemplate: Template 1>
In [7]: plan = SubscriptionPlan.objects.create(name='Bronze')
In [8]: plan
Out[8]: <SubscriptionPlan: Bronze>
In [12]: plan.templates.add(template)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/home/me/GitProjects/test_git/proj/<ipython console> in <module>()

/home/me/GitProjects/test_git/django-trunk/django/db/models/fields/related.pyc in add(self, *objs)
    498         if rel.through._meta.auto_created:
    499             def add(self, *objs):
--> 500                 self._add_items(self.source_field_name, self.target_field_name, *objs)
    501 
    502                 # If this is a symmetrical m2m relation to self, add the mirror entry in the m2m table


/home/me/GitProjects/test_git/django-trunk/django/db/models/fields/related.pyc in _add_items(self, source_field_name, target_field_name, *objs)
    558                         if not router.allow_relation(obj, self.instance):
    559                            raise ValueError('Cannot add "%r": instance is on database "%s", value is on database "%s"' %
--> 560                                                (obj, self.instance._state.db, obj._state.db))
    561                         new_ids.add(obj.pk)
    562                     elif isinstance(obj, Model):

ValueError: Cannot add "<StockTemplate: Template 1>": instance is on database "default", value is on database "None"

Models

  6 class SubscriptionPlan(models.Model):
  7     name = models.CharField(max_length=255)
  8     templates = models.ManyToManyField(StockTemplate)
  9     monthly_fee = models.IntegerField("Monthly Fee", max_length=16, default="0")
 10     modified = models.DateTimeField(auto_now=True, editable=False)
 11     created = models.DateTimeField(auto_now_add=True, editable=False)
 12 
 13     def __unicode__(self):
 14         return "%s" % self.name



 18 class StockTemplate(IKImage):
 19     name = models.TextField()
 20     description = models.TextField(blank=True)
 21 
 22     is_public = models.BooleanField(default=True)
 23 
 24     html = models.FileField(upload_to='stock_templates/html/', \
 25                             help_text='The file that will be used to render.')
 26     #css = models.FileField(upload_to='stock_templates/css/', blank=True)
 27 
 28     img = models.ImageField(upload_to='stock_templates/img/')
 29 
 30     modified = models.DateTimeField(auto_now=True)
 31     created = models.DateTimeField(auto_now_add=True)
 32 
 33     objects = StockTemplateManager()
 34 
 35     class IKOptions:
 36         spec_module = 'editor.specs'
 37         cache_dir = 'stock_templates/img/specs/'
 38         image_field = 'img'
 39 
 40     def __unicode__(self):
 41         return u"%s" % self.name
 42 
 43     def get_absolute_url(self):
 44         return reverse('preview_stock', args=[self.id])

Is it something to do with the fact that StockTemplate is an IKImage object?

  • 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-26T14:01:21+00:00Added an answer on May 26, 2026 at 2:01 pm

    The problem here is that you need to call the method save for both objects before adding the template to the product:

    template.save()
    plan.save()
    plan.templates.add(template)
    

    Django can’t add it if none of those objects has an id (plan and template)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this model: from django.db import models from django.contrib.auth.admin import User # Create your
I have created an editor template for representing selecting from a dynamic dropdown list
I have a Model Book with a virtual attribute for create a Editor from
I installed the (free) Tangible T4 Editor from the VS Gallery, and shut down/restarted
I'm currently using the Rich Text Editor from the YUI framework. But I don't
Is it possible from a keyboard shortcut to switch from the XCode editor window
I need a method to get the data from an external editor. def _get_content():
I'm switching from a Windows PHP-specific editor to VIM, on the philosophy of use
I am copying code from website matplotlib and pasting into the Vim editor in
For a rich text editor that has to handle pasted HTML code from MS

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.