Re: Migrating existing data into Django models

2005-12-13 Thread Grigory Fateyev

Hello tonemcd!
On Tue, 13 Dec 2005 10:27:30 - you wrote:

> 
> I found that any field with primary_key=True leads to a field name
> with _id appended. So your field will look like user_id_id in the
> database.
> 
> Try dropping the '_id' suffix perhaps?
> 
Nop,

Traceback (most recent call last):
  File "/usr/local/bin/django-admin.py", line 5, in ?
management.execute_from_command_line()
  File "/home/greg/www/django_src/django/core/management.py", line 958,
in execute_from_command_lineoutput = action_mapping[action](mod)
  File "/home/greg/www/django_src/django/core/management.py", line 70,
in get_sql_createrel_field = f.rel.get_related_field()
  File "/home/greg/www/django_src/django/core/meta/fields.py", line 846,
in get_related_fieldreturn self.to.get_field(self.field_name)
  File "/home/greg/www/django_src/django/core/meta/__init__.py", line
463, in get_fieldraise FieldDoesNotExist, "name=%s" % name
django.core.meta.FieldDoesNotExist: name=id

-- 
Всего наилучшего!
greg [at] anastasia [dot] ru Григорий.


Re: Migrating existing data into Django models

2005-12-09 Thread Grigory Fateyev

Hello tonemcd!
On Thu, 08 Dec 2005 07:07:41 -0800 you wrote:

> 
> What does your auth model look like?
> 
class User(auth.User):
user_id = meta.CharField(maxlength=12, primary_key=True)
user_active = meta.BooleanField(default=True)
username = meta.CharField(maxlength=25)
user_password = meta.CharField(maxlength=32)
user_session_time = meta.IntegerField()
user_session_page = meta.IntegerField()
user_lastvisit = meta.DateTimeField(default=meta.LazyDate())
user_regdate = meta.DateTimeField(default=meta.LazyDate())
user_level = meta.CharField(maxlength=4)
user_posts = meta.IntegerField()
user_timezone = meta.FloatField(max_digits=5, decimal_places=2)
user_style = meta.CharField(maxlength=4)
[...]

-- 
Всего наилучшего!
greg [at] anastasia [dot] ru Григорий.


Re: Migrating existing data into Django models

2005-12-08 Thread tonemcd

What does your auth model look like?



Re: Migrating existing data into Django models

2005-12-08 Thread Grigory Fateyev

Hello Jacob Kaplan-Moss!
On Tue, 6 Dec 2005 14:16:06 -0600 you wrote:

>   class Story(meta.Model):
>   headline = meta.CharField(maxlength=100, primary_key=True)
>   body = meta.TextField()
> 
> you'll get::
> 
>   CREATE TABLE stories (
>   headline varchar(100) NOT NULL PRIMARY KEY,
>   body text NOT NULL
>   )
>   
> Clear?

I want to use it in my own auth model, but have error: 
> django-admin.py sql auth --settings=anastas.settings
BEGIN;
Traceback (most recent call last):
  File "/usr/local/bin/django-admin.py", line 5, in ?
management.execute_from_command_line()
  File "/home/greg/www/django_src/django/core/management.py", line 958,
in execute_from_command_lineoutput = action_mapping[action](mod)
  File "/home/greg/www/django_src/django/core/management.py", line 70,
in get_sql_createrel_field = f.rel.get_related_field()
  File "django/core/meta/fields.py", line 841, in get_related_field
return self.to.get_field(self.field_name)
  File "/home/greg/www/django_src/django/core/meta/__init__.py", line
463, in get_fieldraise FieldDoesNotExist, "name=%s" % name
django.core.meta.FieldDoesNotExist: name=id

It is possible to fix?

-- 
Всего наилучшего!
greg [at] anastasia [dot] ru Григорий.


Re: Migrating existing data into Django models

2005-12-07 Thread tonemcd

Hi Eric, I did a dig around and found emails from you on the Zope lists
(on my machine) going back to July 2001 - but I know you've been around
longer than that ;)

Yup, it's the primary_key field option I'm using - that seems to work
fine, my only problem now is that PostGres is rather less forgiving of
non-existent foreign keys than MySQL - well, it would be wouldn't it ;)



Re: Migrating existing data into Django models

2005-12-06 Thread Kenneth Gonsalves

On Wednesday 07 Dec 2005 1:51 am, Eric Walstad wrote:
> Nice to see a familiar "face" from the good old Zope days.
>  Welcome to the wonder world of Django.

i have also noticed one or two familiar faces from the good old 
Plone days ;-)

-- 
regards
kg

http://www.livejournal.com/users/lawgon
tally ho! http://avsap.org.in
ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!


Re: Migrating existing data into Django models

2005-12-06 Thread Eric Walstad

On Tuesday 06 December 2005 12:01 pm, tonemcd wrote:
> The primary keys in the
> tables vary, but are mostly varchar.
[...]
> It seems though that Django uses ints for primary keys quite
> extensively, and I guess that will cause some problems with (say)
> creating new entries using the admin system.
>
> Does anyone have any pointers/hints/howtos etc on how to do this with a
> minimum of hassle?

Hi Tone,

Nice to see a familiar "face" from the good old Zope days.  Welcome to the 
wonder world of Django.

I've not used Django with non-integer-pk's yet, but I suspect what your after 
is the "primary_key" field option when defining your Django model.  Have a 
look here:


and search for "primary_key"

Also, there's an "Integrating with a legacy database" section of the docs 
here:


Good luck,

Eric.


Re: Migrating existing data into Django models

2005-12-06 Thread Jacob Kaplan-Moss


On Dec 6, 2005, at 2:01 PM, tonemcd wrote:

It seems though that Django uses ints for primary keys quite
extensively, and I guess that will cause some problems with (say)
creating new entries using the admin system.

Does anyone have any pointers/hints/howtos etc on how to do this  
with a

minimum of hassle?


Although Django uses integer primary keys by default, you can use any  
row as the primary key as long as you're explicit about it::


class Story(meta.Model):
headline = meta.CharField(maxlength=100)
body = meta.TextField()

would map to the following SQL::

CREATE TABLE stories (
id serial NOT NULL PRIMARY KEY, 
headline varchar(100) NOT NULL,
body text NOT NULL
)

(see the automatically added primary key), but if you do this::

class Story(meta.Model):
headline = meta.CharField(maxlength=100, primary_key=True)
body = meta.TextField()

you'll get::

CREATE TABLE stories (
headline varchar(100) NOT NULL PRIMARY KEY,
body text NOT NULL
)

Clear?

Also, if you're working on an existing schema, be sure to the legacy  
database documentation: http://www.djangoproject.com/documentation/ 
legacy_databases/


Jacob