Stefan Matthias Aust wrote:
> Hi,
> 
> Coming from a Java background, I introduced Django in my company for a
> new web application. So far, we made great progress and web
> development suddenly was fun again. Unfortunately, it feels like all
> time I save because of Django, is spent on searching for an IDE (I
> still haven't found something really usable), reading the doc and
> solving trivial Python problems. I hope this will get better once I
> have more experience with Python.
> 
> I've a few questions regarding Django I'd like to ask in this and future 
> mails.
> 
> 1) It is important for me to recreate my environment from scratch
> (that is, from the VCS). I'd like to have a working application after
> calling "syncdb". For my own application, I've create an initial_data
> fixture. But I'd like to recreate users and permissions, too.
> 
> Is this possible?
> 
> I looked into django/core/management.py and it seems that "load_data"
> simple enumerates the installed application so if I want to create a
> fixture for "auth", the initial_data file must be located inside the
> django installation. This isn't an option. Furthermore, it seems that
> "syncdb" always asks for an admin account on the console. Can I
> somehow suppress that question? Instead, I'd like to load some saved
> fixture.
> 
> 2) I'd like to run batch application against our database
> (periodically using cron). Of course, I'd like to use the same
> database abstraction as Django uses, so I tried to find a way to
> initialize the system.
> 
> What's the recommended way to access models from outside of views?
> 
> I came up with these lines (conveniently located inside the project folder):
> 
>  #!/usr/bin/env python
>  ...
>  if __name__ == '__main__':
>    from django.core.management import setup_environ
>    import settings
>    PROJECT_DIRECTORY = setup_environ(settings)
> 
>    from demo.models import Demo
>    d = Demo.objects.get(...)
>    ...
>    d.save()
> 

I just made this.  it should answer most of 1 and 2.
http://code.djangoproject.com/wiki/DatabaseReset

> 3) I need to create an object with a unique random id - and I would
> prefer not to use the database specific SQL layer. What's the best way
> to do it? My naive approach is to declare the id field unique and
> simply try to insert objects until I get no error. The documentation
> says [unique] "is enforced at the database level" but it unfortunately
> does not describe what happens if the constraint is violated. Will
> this always raise an IntegrityError?
> 

Why a unique _random_ id.  seems odd.  knowing the use case might help.

> 4) I'd like to specify the file name of an uploaded file. Right now,
> the original filename is kept and I think, this could cause problems
> if two people upload a file with the same name at the same time.
> 
> I tried to understand the file upload process in the Django source but
> there was too much meta magic for my brain. However, it seems that the
> current documentation doesn't tell the whole story. It seems, that
> there is a save_FOO_file() in addition to the documentation tree
> get_FOO_xxx methods... My guess is that manipulators.py is responsible
> for saving the uploaded file. ... Wait, I think, _save_FIELD_file()
> will eventually save the file and yes, that while loop is obviously
> not threadsafe! So I need to set the filename myself. But how?
> 

good Q  hopfully someone can answer it. :)

Carl K

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