django models CharField

313 Views Asked by At

I am trying to create a django slideshow app using some existing code and adding some new. I am unsure if what I am doing is correct, I think the problem is in my models.py and as a python beginner I think I need some advice.

models.py

from django.db import models
import datetime

class Slider(models.Model):
    title = models.CharField(max_length=100)
    description = models.TextField(blank=True)
    slideshow = models.ForeignKey('Slideshow')
    images = models.ImageField(upload_to='slideshow', max_length=1000, blank=True, null=True)

def __unicode__ (self):
    return self.title

class Slideshow(models.model):
    name = models.CharField(max_length=50)
    touchEnabled = models.BooleanField(blank=True, default=False)

    speed = models.IntegerField(blank=True, default=500)

    class wrapperClass_options(models.Model):
        choices = (('mydiv'))  

    wrapperClass = models.CharField(blank=True, max_length=20, default=choices)
    # div class to wrap the slider in. Change it to prevent using default styles.

    pub_date = models.DateTimeField(auto_now=True)

def __unicode__(self):
    return self.name

I am pretty sure that my BooleanField and IntegerField are ok, but am not so sure about the CharField.

the charfield default is #mydiv but it needs to be able to be changed to whatever a developer needs it to be, am I doing the right thing by creating wrapperclass_options and adding the default to it choices = 'mydiv' or should I be doing something different altogether?

Below is my admin.py

admin.py

from satchmo_slideshow.models import Slider, Slideshow
from django.contrib import admin

class SlideInline(admin.StackedInline):
    model = Slider

class SlideshowAdmin(admin.ModelAdmin):
    fieldsets = [(title, {'fields': ['name']}),
        ('speed', {'fields': ['Default: 500ms']}),
        ('wrapperClass', {'fields': ['Default: mydiv']}),
        ('touchEnabled', {'fields': ['Default: False']}),      
             ]

   inlines = [SlideInline]
    list_display = ['name', 'pub_date']
    list_filter = ['pub_date']
    search_fields = ['name']

admin.site.register(Slideshow, SlideshowAdmin)

using python 2.7 and django 1.4.2

0

There are 0 best solutions below