Question

I have category model, in which I want to load some default data. How can I achieve it? This is model is for a select box, which is extensible for different applications later

This is the model I have designed it, I tried verifying choice

class Category(db.Model):
    categorylist=db.StringListProperty()

Please help.

Thank You

Was it helpful?

Solution

Select Box Model



Class Category (db.Model):
       name = db.StringProperty()

Right now, I use this in this fashion (I'm using Django Framework).

In the views.py I make an array


options =["Car", "Motor Bikes", "Bikes", "Apparel"]   

and in the templates I populate it this way


{% for option in options %}
   {% ifequal edit_nw.category option %}
         {{option}}
    {% else %}
         {{option}}     
    {% endifequal %}
{% endfor %}

All I want is to use this options to be a result of model like Category.all(), should have some default data loaded for the entire app. If necessary, Ill add categories from admin panel

OTHER TIPS

Check out the docs. There is default attribute for property.

default
A default value for the property. If the property value is never given a value, or is given a value of None, then the value is considered to be the default value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top