Managed to fix it.  Had a hunt in the django code for what the admin
modules does and discovered the Model.objects.get_or_create function.
Now works perfectly!


On 13/12/2007, Tane Piper <[EMAIL PROTECTED]> wrote:
> Ok, I've modified this slightly, however still cannot get this to
> work.  To test it, I put a print statement at the top of the function
> and called syncdb, and sure enough the function was being called 8
> times!
>
> So, I modified it so each import is a function, and each has it's own
> dispatcher with a sender (being IssueType, IssueSeverity and
> IssueStatus) - however when the models are created they don't get
> called.  Take the sender away and each function gets called 8 times -
> very strange.
>
> Can anyone help?????
>
>
> On 13/12/2007, Tane Piper <[EMAIL PROTECTED]> wrote:
> > Hi folks,
> >
> > In our app, we're building a simple Issue list app, and within the app
> > we want to add some basic entries for issue type, issue status and
> > issue severity.  Within our /issue directory, I have created a
> > management.py file and added this:
> >
> > from django.dispatch import dispatcher
> > from django.db.models import signals
> >
> > from hgfront.issue.models import *
> >
> > def init_issues_database():
> >     """This injects the database with default values for issues"""
> >     issue_types = (
> >         ('Bug', 0),
> >         ('Enhancment', 1),
> >         ('Feature Request', 2),
> >         ('Typo', 3)
> >     )
> >     for issue in issue_types:
> >         p = IssueType(title = issue[0], order=issue[1])
> >         p.save()
> >
> >     sev_types = (
> >         ('Minor', 0),
> >         ('Medium', 1),
> >         ('Major', 2),
> >         ('Critical', 3),
> >         ('Blocker', 4)
> >     )
> >     for sev in sev_types:
> >         s = IssueSeverity(title = sev[0], order=sev[1])
> >         s.save()
> >
> >     status_types = (
> >         ('Raised', 0),
> >         ('Accepted', 1),
> >         ('Not Accepted', 2),
> >         ('Fixed', 3),
> >         ('Works For Me', 4)
> >     )
> >     for status in status_types:
> >         t = IssueStatus(title = status[0], order=status[1])
> >         t.save()
> >
> > dispatcher.connect(init_issues_database, signal=signals.post_syncdb)
> >
> > The problem is, when I do syncdb, the items do get added to the
> > database, but for issue_types instead of just 4 entries, 36 entries go
> > in.  For sev_types and status_types 40 entries go in each instead of
> > 5.  From what I can work out, it seems to be looping and adding a full
> > entry for each item within the tuples.
> >
> > Cannot work this one out at all so either - a) it's a bug or b) we're
> > using management.py wrong, and if so can anyone please point us in the
> > right direction and I can't find any docs on it.
> >
> > --
> > Tane Piper
> > Blog - http://digitalspaghetti.me.uk
> > AJAX Pastebin - http://pastemonkey.org
> >
> > This email is: [ ] blogable [ x ] ask first [ ] private
> >
>
>
> --
> Tane Piper
> Blog - http://digitalspaghetti.me.uk
> AJAX Pastebin - http://pastemonkey.org
>
> This email is: [ ] blogable [ x ] ask first [ ] private
>


-- 
Tane Piper
Blog - http://digitalspaghetti.me.uk
AJAX Pastebin - http://pastemonkey.org

This email is: [ ] blogable [ x ] ask first [ ] private

--~--~---------~--~----~------------~-------~--~----~
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