python - Django model class and custom property -


Howdy - There was a strange problem for me today:

I have a model class in Django Added a custom asset that should not be saved in the database and therefore is not shown in the model structure:

  class category (models.model): groups = model.mindomoneyfield (group) Title: Now, when I am under Shell or writing a test and I do the following:  
  c1 = class.objects  

() C1 . Title ['de'] = 'German title' print c1.title ['de'] # print "German title" c2 = category.bags.create () print c2.title ['de'] # print "German title" & Lt; - WTF?

It seems that 'title' is of global type if I change the title to a simple string that does the expected work, should he do something? I also tried to set the title as a property:

  title = property (_title)  

but even if that was not working then How can I solve this? Thank you in advance!

Edit:

According to the request, the base problem is intended to make you better available to the surrounding environment: In our model structure we have a model class that translates Stores. This class is unbound from all other sections which are related to each other, translation class classifies the translated value, a language key, a translation key and translation and package. Some model sections may have properties that can be translated into different languages. These properties have not been mapped within the Django model structure because it is not really possible in our eyes. With each of these classes translatable qualities, let's call them translatable, one or more of these properties can be. This is the translation key, for example, if a translitable property is "title" in a class category, then the model translation "module. Anywhere anywhere" as a package / class, the form of the translation key as "title" Will store in, and e.g. My goal for German translation value "Category" and language key "D" is to reduce access to these properties. So this is a way of solving all the model class "plain" classes "in this module path and class name (for later storage in the translation database table), and the" _properties "method which takes the name of the property a class" Translator "which is unique for each translitable property name. This class translation model resolves the actual translation value from the model and currently selects the language Do some stuff to automatically solve the translation.

Do not do this like this Title attribute is completely "global"

  class category (models.model): group = model.monitomyfield (group). This is part of the group, each Not a part of the example. 

@property def Title (self): Refund auto. _title def save (self, * args, ** kW): Try: excluding attribute yourself _ Title: self._title = defaultdict () super (category, self). Save (* If you can define the case of your real usage, then it is possible that it is a great Could make the deal easier.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -