Tuesday, July 22, 2014

Different choices values for a single field in inherited class

Hello,                                                                                                                                                                                                             
                                                                                                                                                                                                                   
I'm writing my first webapplication{, in Django} and I'm faced with a                                                                                                                                              
problem that I can't manage alone.                                                                                                                                                                                 
                                                                                                                                                                                                                   
I want to write an application for classifying my wine. There, a wine could                                                                                                                                       
be red or white and regarding this parameter a wine have a more                                                                                                                                                    
specific tone choice, let say for a red wine could be ligth red or                                                                                                                                                 
dark red...                                                                                                                                                                                                        
                                                                                                                                                                                                                   
Here is the idea I want to wrote                                                                                                                                                                                   

$ wine/models.py:
class Color(models.Model):    
       
class Meta:                                                                                                                                                                                                      abtract = true                                                                                                                                                                                    
        tone    
= models.CharField(max_length = 32, choices = SOMETHING)                                                                                                                                          
class RedColor(Color):                                                                                                                                                                                          R_COLORS = (                                                                                                                                                                                    
               
("Light red",    "light red"),                                                                                                                                                          
               
("Dark red",     "dark red")                                                                                                                                                              )                                                                                                                                                                                                            
 
# Tells the parents class that SOMETHING = R_COLORS for red wines              
 
class WhiteColor(Color):                                                                                                                                                                                        W_COLORS = (                                                                                                                                                                                                  ("Ligth white",  "ligth white"),                                                                                                                                                                        ("Dark white",   "dark white")                                                                                                                                                              )                                                                                                                                                                                                                # Tells the parents class that SOMETHING = W_COLORS for white                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
My problems are that I can't manage to write this idea in correct                                                                                                                                                  
Python/Django.                                                                                                                                                                                                     
                                                                                                                                                                                                                   
Also I'm far to be sure that this is the good way of storing this                                                                                                                                                  
information. I'm not sure that 2 tables for storing the same kind of                                                                                                                                               
data is a good way of designing databases.                                                                                                                                                                         
                                                                                                                                                                                                                   
If someone could lead me on some directions it will be great ! 

Thanks                                                                                                                                                   
                                                                                                                                                                                                                   
PS: I will have the same problems on other table on the application,                                                                                                                                               
for example the grappe variety.                                                                                                                                                                                    
                                                                                                                                                                                                                   
PPS: I will have the same problem for building the next application                                                                                                                                                
for classifying my beers.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fc4373a6-aaff-4e1d-b2bf-872edcc5a725%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment