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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:22:49+00:00 2026-05-15T10:22:49+00:00

today a weird problem occurred to me: I have a model class in Django

  • 0

today a weird problem occurred to me:

I have a model class in Django and added a custom property to it that shall not be saved into the database and therefore is not representative in the model’s structure:

class Category(models.Model):
    groups = models.ManyToManyField(Group)
    title = defaultdict()

Now, when I’m within the shell or writing a test and I do the following:

c1 = Category.objects.create()
c1.title['de'] = 'german title'
print c1.title['de'] # prints "german title"

c2 = Category.objects.create()  
print c2.title['de'] # prints "german title" <-- WTF?

It seems that ‘title’ is kind of global. If I change the title to a simple string it works as expected, so it has to do something with the dict? I also tried setting title as a property:

title = property(_title)

But that did not work, too. So, how can I solve this? Thank you in advance!

EDIT:

Here is the intention of the base problem to provide you with a better look at the whole surrounding environment as requested:
In our model structure, we have a model class that stores translations. This class is unbound from all the other classes that have relations with each other. The translation class stores the translated value, a language key, a translation key and the package and class the translation belongs to. Some model classes can have properties that can be translated into different languages. These properties are not mapped within the Django model structure as this is not truly possible in our eyes. Each of these classes with translatable properties, let’s call them translatable, can have one or more of these properties. That’s what the translation key is for. E.g. if there is a class Category with a translatable property "title", the model translation will store "module.somewhere.Category" as package/class, "title" as translation key, and e.g. for german the translation value "Kategorie" and the language key "de".
My aim is to ease the access to these properties. So all these model classes inherit from a plain class called "Translatable". It has a method for resolving the module path and name of the class (for the later storing within the translation database table) and a "_propertize" method that takes the name of the property. Properties instantiate a class "Translator" that is unique for each translatable property name. This class does the resolving of the real translation value from the translation model class and some stuff for automatically resolving the translation of the currently chosen language.

  • 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-15T10:22:50+00:00Added an answer on May 15, 2026 at 10:22 am

    Don’t do it that way. Your title attribute is completely “global”. It’s part of the class, not part of each instance.

    Do something like this.

    class Category(models.Model):
        groups = models.ManyToManyField(Group)
        @property
        def title(self):
            return self._title
        def save( self, *args, **kw  ):
            try:
                self._title
            except AttributeError:
                self._title= defaultdict()
            super( Category, self ).save( *args, **kw )
    

    If you could define your actual use case, it might be possible to simplify this a great deal.

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

Sidebar

Related Questions

No related questions found

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.