Thank you all for quick responses. I feel a bit silly trying to put
unique=true for a boolean.

What I was trying to accomplish though: Only one value can have the
boolean set to "true".

Also (here I am taking the whole hand when you guys have offered a
finger) ... have any of you implemented some kind of custom position/
order element into an object accessible from the admin interface?

On Jul 12, 11:43 pm, oggie rob <[EMAIL PROTECTED]> wrote:
> The statements seem fine, just that your models don't reflect what you
> are after.
>
> 1. if you set null=True, the database lines would read "NULL" instead
> of "NOT NULL". blank=True refers to whether the value can be empty
> (i.e. NULL is not equal to ''). However for most CharFields you will
> want to keep it saying "NOT NULL".
> 2. the field "front" is a boolean field, but also is unique. You can't
> have more than two entries (and obviously one has to be True, one
> False), but you are seeing it after only one entry because both the
> first and second records are False.
>
>  -rob
>
> On Jul 12, 3:22 pm, Jökull <[EMAIL PROTECTED]> wrote:
>
> > 1. All fields have 'NOT NULL' and are required - this does not reflect
> > my model
> > 2. I get strange errors in the admin when adding a second item of
> > anything : IntegrityError at /admin/portfolio/work/add/ (1062,
> > "Duplicate entry '0' for key 2")
>
> > portfolio/models.py
> > ---------------------------
>
> > from django.db import models
> > import datetime
> > import os
>
> > # Create your models here.
>
> > class Tag(models.Model):
> >         title = models.CharField('Titill',maxlength=100,unique=True)
> >         slug = models.SlugField(prepopulate_from=('title',))
>
> >         def __unicode__(self):
> >                 return self.title
> >         class Admin:
> >                 pass
>
> > class Portfolio(models.Model):
> >         created_date = models.DateTimeField(auto_now_add=True)
> >         title = models.CharField('Titill',maxlength=100)
> >         slug =
> > models.SlugField(prepopulate_from=('title',),unique_for_date='created_date',)
> >         hidden = models.BooleanField('Fela',default=False)
>
> >         def __unicode__(self):
> >                 return self.title
> >         class Admin:
> >                 pass
>
> > class Work(models.Model):
> >         created_date = models.DateTimeField(auto_now_add=True)
> >         image = models.ImageField('Mynd',upload_to='upload/images/
> > work/',help_text='Aðeins uploada JPEG myndum (með .jpg endingu)')
> >         title = models.CharField('Titill',maxlength=100)
> >         subtitle = models.CharField('Undirtitill',maxlength=100,blank=True)
> >         description = models.TextField('Lýsing',blank=True)
> >         hidden = models.BooleanField('Fela',default=False)
> >         front = models.BooleanField('Á forsíðu',default=False,unique=True)
> >         tags = models.ManyToManyField(Tag,blank=True,verbose_name='Flokkar')
> >         portfolio = models.ForeignKey(Portfolio)
>
> >         def __unicode__(self):
> >                 return '%s - %s' % (self.title,self.portfolio)
> >         def thumbnail(self):
> >                 file_path = self.get_image_url()
> >                 file, ext = os.path.splitext(file_path)
> >                 file = file + "_thumb_128x128.jpg"
> >                 if(file_path):
> >                         return '<a href="%s" target="_blank"><img src="%s" 
> > /></a>' %
> > (file_path, file)
> >         thumbnail.short_description = 'Mynd'
> >         thumbnail.allow_tags = True
> >         class Admin:
> >                 list_display = ('__unicode__','portfolio','thumbnail')
> >         class Meta:
> >                 ordering = ['title']
>
> > class Event(models.Model):
> >         created_date = models.DateTimeField(auto_now_add=True)
> >         start_date = models.DateField('Opnunardagur')
> >         end_date = models.DateField('Lokunardagur')
> >         title = models.CharField('Titill',maxlength=100)
> >         slug =
> > models.SlugField(prepopulate_from=('title',),unique_for_month='created_date')
> >         portfolios = models.ManyToManyField(Portfolio,blank=True)
> >         description = models.TextField('Lýsing',blank=True)
> >         hidden = models.BooleanField('Fela',default=False)
>
> >         def __unicode__(self):
> >                 return self.title
> >         def publish_status(self):
> >                 if (self.end_date >= datetime.date.today()) & 
> > (self.start_date <=
> > datetime.date.today()):
> >                         return '<strong>Sýning í gangi</strong>'
> >                 elif (self.start_date > datetime.date.today()):
> >                         return 'Sýning ekki farin í gang'
> >                 elif (self.end_date < datetime.date.today()):
> >                         return 'Sýning búin'
> >         publish_status.short_description = 'Tímasetning'
> >         publish_status.allow_tags = True
> >         def duration(self):
> >                 return self.end_date - self.start_date
> >         duration.short_description = 'Tímalengd'
> >         class Meta:
> >                 ordering = ['-start_date']
> >         class Admin:
> >                 list_display =
> > ('__unicode__','start_date','end_date','duration','publish_status')
>
> > class Artist(models.Model):
> >         created_date = models.DateTimeField(auto_now_add=True)
> >         name = models.CharField('Nafn',maxlength=100)
> >         slug = models.SlugField(prepopulate_from=('name',),unique=True)
> >         file = models.ImageField('CV',upload_to='upload/images/
> > artist/',help_text='Aðeins uploada JPEG myndum (með .jpg endingu)')
> >         email = models.EmailField()
> >         portfolios = models.ManyToManyField(Portfolio,blank=True)
>
> >         def __unicode__(self):
> >                 return self.name
> >         class Meta:
> >                 ordering = ['name']
> >         class Admin:
> >                 pass
>
> > $ python manage.py sql portfolio
> > -------------------------------------------
>
> > BEGIN;
> > CREATE TABLE `portfolio_work` (
> >     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> >     `created_date` datetime NOT NULL,
> >     `image` varchar(100) NOT NULL,
> >     `title` varchar(100) NOT NULL,
> >     `subtitle` varchar(100) NOT NULL,
> >     `description` longtext NOT NULL,
> >     `hidden` bool NOT NULL,
> >     `front` bool NOT NULL UNIQUE,
> >     `portfolio_id` integer NOT NULL
> > )
> > ;
> > CREATE TABLE `portfolio_portfolio` (
> >     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> >     `created_date` datetime NOT NULL,
> >     `title` varchar(100) NOT NULL,
> >     `slug` varchar(50) NOT NULL,
> >     `hidden` bool NOT NULL
> > )
> > ;
> > ALTER TABLE `portfolio_work` ADD CONSTRAINT
> > portfolio_id_refs_id_3865019b FOREIGN KEY (`portfolio_id`) REFERENCES
> > `portfolio_portfolio` (`id`);
> > CREATE TABLE `portfolio_tag` (
> >     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> >     `title` varchar(100) NOT NULL UNIQUE,
> >     `slug` varchar(50) NOT NULL
> > )
> > ;
> > CREATE TABLE `portfolio_event` (
> >     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> >     `created_date` datetime NOT NULL,
> >     `start_date` date NOT NULL,
> >     `end_date` date NOT NULL,
> >     `title` varchar(100) NOT NULL,
> >     `slug` varchar(50) NOT NULL,
> >     `description` longtext NOT NULL,
> >     `hidden` bool NOT NULL
> > )
> > ;
> > CREATE TABLE `portfolio_artist` (
> >     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> >     `created_date` datetime NOT NULL,
> >     `name` varchar(100) NOT NULL,
> >     `slug` varchar(50) NOT NULL UNIQUE,
> >     `file` varchar(100) NOT NULL,
> >     `email` varchar(75) NOT NULL
> > )
> > ;
> > CREATE TABLE `portfolio_work_tags` (
> >     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> >     `work_id` integer NOT NULL REFERENCES `portfolio_work` (`id`),
> >     `tag_id` integer NOT NULL REFERENCES `portfolio_tag` (`id`),
> >     UNIQUE (`work_id`, `tag_id`)
> > )
> > ;
> > CREATE TABLE `portfolio_event_portfolios` (
> >     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> >     `event_id` integer NOT NULL REFERENCES `portfolio_event` (`id`),
> >     `portfolio_id` integer NOT NULL REFERENCES `portfolio_portfolio`
> > (`id`),
> >     UNIQUE (`event_id`, `portfolio_id`)
> > )
> > ;
> > CREATE TABLE `portfolio_artist_portfolios` (
> >     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
> >     `artist_id` integer NOT NULL REFERENCES `portfolio_artist` (`id`),
> >     `portfolio_id` integer NOT NULL REFERENCES `portfolio_portfolio`
> > (`id`),
> >     UNIQUE (`artist_id`, `portfolio_id`)
> > )
> > ;
> > COMMIT;


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to