views:

26

answers:

1

I have the following model.

from django.db import models

class Client(models.Model):
    postcode = models.CharField(max_length=10)  
    first_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)
    address = models.TextField(blank=True)
    phone = models.IntegerField(blank=True)
    email = models.EmailField(blank=True)
    url = models.URLField(blank=True)
    client_since = models.DateTimeField('Client Since')

    def __unicode__(self):
        return self.first_name

def client_since(self):
    return self.client_since.date() == datetime.date.today()

class Contractor(models.Model):
   postcode = models.CharField(max_length=10)   
   first_name = models.CharField(max_length=100)
   last_name = models.CharField(max_length=100)
   address = models.TextField(blank=True)
   phone = models.IntegerField(blank=True)
   email = models.EmailField(blank=True)
   contractor_since = models.DateTimeField('Contractor Since')

   def __unicode__(self):
       return self.first_name

   def contractor_since(self):
       return self.contractor_since.date() == datetime.date.today()

I run 'python manage.py validate' gives me - 0 errors found

Then I run 'python manage.py sql "appname" and I get to see my tables...

BEGIN;
CREATE TABLE "schedule_client" (
    "id" integer NOT NULL PRIMARY KEY,
    "postcode" varchar(10) NOT NULL,
    "first_name" varchar(100) NOT NULL,
    "last_name" varchar(100) NOT NULL,
    "address" text NOT NULL,
    "phone" integer NOT NULL,
    "email" varchar(75) NOT NULL,
    "url" varchar(200) NOT NULL,
    "client_since" datetime NOT NULL
 )
 ;
 CREATE TABLE "schedule_contractor" (
     "id" integer NOT NULL PRIMARY KEY,
     "postcode" varchar(10) NOT NULL,
     "first_name" varchar(100) NOT NULL,
     "last_name" varchar(100) NOT NULL,
     "address" text NOT NULL,
     "phone" integer NOT NULL,
     "email" varchar(75) NOT NULL
 )
 ;
 COMMIT;

But I don't see "contracor_since in the contractor table ... db field being created??? I tried several times, I am using django 1.1.1 on OS X leopard.

What I am doing wrong?

+3  A: 

You are shadowing the model attribute by a function definition using the same name. Try change either the function name or your model attribute (contractor_since).

The MYYN
Sorry I am new to django. Could you please explain what do you mean by "shadowing the model attribute". Thanks.
wailer
Got it. Google and Django doc did the explaining. Thanks.
wailer