Created
November 28, 2013 21:13
-
-
Save AndrewBMartin/7698173 to your computer and use it in GitHub Desktop.
model.py and application_admin.py for camelot Videostore Tutorial
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 camelot.view.art import Icon | |
from camelot.admin.application_admin import ApplicationAdmin | |
from camelot.admin.section import Section | |
from camelot.core.utils import ugettext_lazy as _ | |
class MyApplicationAdmin(ApplicationAdmin): | |
name = 'Videostore' | |
application_url = 'http://www.python-camelot.com' | |
help_url = 'http://www.python-camelot.com/docs.html' | |
author = 'Andrew' | |
domain = 'mydomain.com' | |
def get_sections(self): | |
from camelot.model.memento import Memento | |
from camelot.model.party import Person, Organization | |
from camelot.model.i18n import Translation | |
from videostore.model import Movie, Director | |
return [ Section( _('Movies'), | |
self, | |
Icon('tango/22x22/mimetypes/x-office-presentation.png'), | |
items = [Movie, Director] ), | |
Section( _('Relation'), | |
self, | |
Icon('tango/22x22/apps/system-users.png'), | |
items = [Person, Organization]), | |
Section( _('Configuration'), | |
self, | |
Icon('tango/22x22/categories/preferences-system.png'), | |
items = [Memento, Translation] ) | |
] | |
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 sqlalchemy import Unicode, Date, Integer | |
from sqlalchemy.schema import Column | |
import sqlalchemy.types | |
from camelot.admin.entity_admin import EntityAdmin | |
from camelot.core.orm import Entity | |
import camelot.types | |
from sqlalchemy.schema import ForeignKey | |
from sqlalchemy.orm import relationship | |
class Movie ( Entity ): | |
__tablename__ = 'movie' | |
title = Column( Unicode(60), nullable = False ) | |
short_description = Column( Unicode(512) ) | |
release_date = Column( Date() ) | |
genre = Column( Unicode(15) ) | |
director_id = Column( Integer, ForeignKey('director.id')) | |
director = relationship( 'Director' ) | |
#backref = 'movies' ) | |
def __unicode__( self ): | |
return self.title or 'Untitled movie' | |
class Admin( EntityAdmin ): | |
from movie_summary import MovieSummary | |
verbose_name = 'Movie' | |
list_display = ['title', | |
'short_description', | |
'release_date', | |
'genre', | |
'director'] | |
form_actions = [MovieSummary()] | |
def __unicode__(self): | |
return self.title or 'untitled movie' | |
class Director( Entity ): | |
__tablename__ = 'director' | |
name = Column( Unicode( 60 ) ) | |
movies = relationship( 'Movie' ) | |
class Admin( EntityAdmin ): | |
verbose_name = 'Director' | |
list_display = ['name'] | |
# form_display = list_display + ['movies'] | |
def __unicode__(self): | |
return self.name or 'unknown director' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment