Hi!

I am trying to make a model that is a resource, for example a video file, 
or a PDF document, which has a category, for example Math or Science or 
Computer Science.

What I want to ask is how do I have multiple categores to a single item, 
using charfield and choice.

Here is an example of the code:
class ResourceItem(models.Model):

    # Choices
    RESOURCE_OPTIONS = (
        ('VID', 'Video'),
        ('AUD', 'Audio'),
        ('TXT', 'PDF, DOC, TXT etc.'),
    )

    CATEGORY_TYPE = (
        ('SCI', 'General Science'),
        ('MAT', 'Mathematics'),
        ('PHY', 'Physics'),
        ('CHE', 'Chemistry'),
        ('CSCI', 'Computer Science'),
    )

    # Model attributes
    title = models.CharField(max_length=255)
    link = models.URLField(max_length=200)
    resource_type = models.CharField(max_length=10, 
choices=RESOURCE_OPTIONS)
    category = models.ManyToManyField(models.CharField(max_length=10, 
choices=CATEGORY_TYPE))

Is simply creating it as a ManyToManyField the right way to do things (take 
a look at category field type)? I feel that this is not the right way to do 
things. Any help would be appreciated. For a better picture of the code, I 
have also created a link on dpaste <https://dpaste.de/4fI45/>, if you 
prefer color that is.

-- 
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+unsubscr...@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.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to