-
-
Save jorisvddonk/9fad25e43f30856e29eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from polls.models import Poll | |
from polls.models import Choice | |
class ChoiceInline(admin.StackedInline): | |
model = Choice | |
extra = 0 | |
class PollAdmin(admin.ModelAdmin): | |
inlines = [ChoiceInline] | |
admin.site.register(Poll, PollAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
import datetime | |
from django.utils import timezone | |
from s3direct.fields import S3DirectField | |
class Poll(models.Model): | |
question = models.CharField(max_length=200) | |
pub_date = models.DateTimeField('date published') | |
def __unicode__(self): # Python 3: def __str__(self): | |
return self.question | |
def was_published_recently(self): | |
now = timezone.now() | |
return now - datetime.timedelta(days=1) <= self.pub_date <= now | |
was_published_recently.admin_order_field = 'pub_date' | |
was_published_recently.boolean = True | |
was_published_recently.short_description = 'Published recently?' | |
class Choice(models.Model): | |
poll = models.ForeignKey(Poll) | |
choice_text = models.CharField(max_length=200) | |
votes = models.IntegerField(default=0) | |
image = S3DirectField(upload_to='images_s3direct') | |
def __unicode__(self): # Python 3: def __str__(self): | |
return self.choice_text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment