Cats and Code » databases http://blog.gorwits.me.uk by Oliver Gorwits Sat, 29 Mar 2014 23:28:44 +0000 en-US hourly 1 http://wordpress.org/?v=3.6.1 Hosting the AutoCRUD Demo http://blog.gorwits.me.uk/2011/10/19/hosting-the-autocrud-demo/?utm_source=rss&utm_medium=rss&utm_campaign=hosting-the-autocrud-demo http://blog.gorwits.me.uk/2011/10/19/hosting-the-autocrud-demo/#comments Wed, 19 Oct 2011 18:19:59 +0000 Oliver Gorwits http://blog.gorwits.me.uk/?p=680 Continue reading ]]> In my previous entry here (syndicated from blogs.perl.org), I linked at the end to a demo Catalyst::Plugin::AutoCRUD application running on DotCloud. I’m much happier with this than running something on my own personal server, and here’s the notes on its setup.

For those unfamiliar, DotCloud is a Platform as a Service (PaaS) offering a freemium model. I’m grateful to them for this as the free account provides all I need for my demo.

First, I followed to the letter Phillip Smith’s comprehensive guide on deploying a Perl Catalyst application to the DotCloud service. Next I customised the basic application created in the guide to use AutoCRUD:

  • removed the Root controller
  • added two Models and their supporting DBIx::Class Result classes
  • set basepath in the configuration
  • installed an hourly cron job to:
    • restore the SQLite databases
    • restart the web service (supervisorctl restart uwsgi)

Next I wanted a more tidy looking domain for the demo, so purchased autocrud.pl through NETIM. My plan is to have demo.autocrud.pl pointing to the DotCloud instance, and sometime in the future to have autocrud.pl be used for a secret feature I’m still working on. Sadly NETIM only offers HTTP redirects from subdomains, so I delegated hosting of the DNS to ClouDNS.

ClouDNS is another freemium service, again where the free part provides just what I need. They offer not only a bit of a smarter interface than NETIM for DNS zone management, but also HTTP redirects from the zone apex.

I do of course know that nothing lasts forever, particularly with freemium services, and I’m grateful for what’s available because it works very well (I’ve added promotional icons for ClouDNS and DotCloud to the demo site).

The end result of this is that I now have the AutoCRUD demo safely hosted on DotCloud with a friendly URL to pass out in documentation or blog posts :-)

]]>
http://blog.gorwits.me.uk/2011/10/19/hosting-the-autocrud-demo/feed/ 0
Django Admin App Views http://blog.gorwits.me.uk/2011/03/03/django-admin-app-views/?utm_source=rss&utm_medium=rss&utm_campaign=django-admin-app-views http://blog.gorwits.me.uk/2011/03/03/django-admin-app-views/#comments Thu, 03 Mar 2011 09:29:13 +0000 Oliver Gorwits http://blog.gorwits.me.uk/?p=422 Continue reading ]]> Following my previous post about configuring Django models, I’m now ready to work on the view. Remember, this is simply within the “Admin” app which ships with Django, and below is a non-exhaustive set of options:

ModelAdmin Derived Class Options

For the list screen:

  • list_display = ('field1', 'field2')
  • list_display_links = ['field2']
  • list_editable = ['field2']
  • list_filter = ('field1', 'field2')
  • list_per_page = 20
  • search_fields = ['field1', 'foreign_key__fieldname']

For the edit screen, it’s possible to control the form layout and displayed fields:

fieldsets = (("Title"|None, options), )
options = {
    fields : (('one', 'line', 'together'), 'field5', 'field6'),
    classes : ['collapse', 'wide']
}

or use the following:

fields = ('field1', 'field2')
exclude = ('field3', 'field4')

And some other edit screen options:

  • filter_horizontal|filter_vertical = ('multi_select_field')
  • radio_fields = ('fk_field', 'choice_field')
  • save_on_top = True

For further details, see the Admin App documentation. Also useful are the Custom Actions documentation, the DB Queries documentation, and the QuerySet documentation.

]]>
http://blog.gorwits.me.uk/2011/03/03/django-admin-app-views/feed/ 0
Django Models http://blog.gorwits.me.uk/2011/03/02/django-models/?utm_source=rss&utm_medium=rss&utm_campaign=django-models http://blog.gorwits.me.uk/2011/03/02/django-models/#comments Wed, 02 Mar 2011 14:38:53 +0000 Oliver Gorwits http://blog.gorwits.me.uk/?p=416 Continue reading ]]> I’ve been working on a small Django app recently, and started by cleaning up its model definitions. Here’s a quick (but not exhaustive) list of useful configuration options:

Model Meta Options

  • db_table = "string"
  • managed = False (whether SQL is generated by the manage.py app)
  • ordering = ['column1', '-column2'] (NB admin app only uses the first)
  • order_with_respect_to = 'fk_field'
  • unique_together = (('column1', 'column2'), )
  • verbose_name = "String"
  • verbose_name_plural = "String"
  • abstract = True

Common Field Options

  • null = True
  • blank = True
  • choices = (('db_val', 'displayed_val'), )
  • db_column = "string"
  • db_index = True
  • default = "string"
  • editable = False
  • primary_key = True
  • unique = True
  • verbose_name = "String"

Field Types and Options

  • AutoField
  • BooleanField
  • CharField (max_length=integer)
  • DateField|DateTimeField(auto_now_add=True)
  • IPAddressField
  • PositiveIntegerField
  • TextField
  • ForeignKey(Class, to_field='related_field')
  • ManyToManyField(Class, to_field='related_field')

For further details, see the Models documentation, Meta Options documentation and Field Types documentation.

]]>
http://blog.gorwits.me.uk/2011/03/02/django-models/feed/ 0