Re: field mapping to multiple columns?

2009-10-07 Thread J. Hall of Carlisle MA


You bring up a very interesting question It seems to make little sense
to put this kind of data into a table of it's own. The ORM usually
maps a class to a table. in this case you want to map the class to a
group of columns in a single table.

How do you use a class based compound data type and store it flat in
the database but in separate database native fields?  I don't know. (I
am new to dajango., but am experienced with web development and
python.)

One solution is to subclass the python class for time deltas with code
that maps the data to fields in a table. Call this class
time_delta_mapped or some such.This class should serve as an abstract
base class. After this subclass this class for every time that you
would use it in your model. Use a primary key of the time data table
equal to the primary key of the table you might naturally include the
data. Code it so that a row is created in the time data table(s) for
each row in the other table.
I am not certain that a table would not be created for the abstract
base class and the data from all the subclasses coul end up in the
table corresponding to that class. This would be silly. and not what
is wanted so you may end up with cut and paste coding if that can't be
avoided.

Another approach to the specific problem would be to use a python
class for time deltas and then pickle it and put it into a single
field. I would not mold your model around the way a data-type unique
to postgres works. If you are using postgres then you can access the
type  What sort of role will this field have in your model? Will it be
an index, order or groupby field? Is your database going to be 100%
dajango / python?. If you are going to access the database via sql or
reporting software or if it is computationally significant in reports
then I would not use pickle into a single field.

Another approach seems to me to be that you could possibility create
an aspect or decorator that would handle any fields named the right
way to create an attribute of the correct class. If anyone knows of
examples of this or has it working i'd love to read the code!


On Oct 7, 9:04 pm, akonsu  wrote:
> hello,
>
> i need a datetime field with an associated precision value. the
> precision shows which parts of the datatime field are used. in other
> words, my datatime field can contain just a year, or a year and a
> month, etc. similar to postgres' DATE_TRUNC function. i know i can
> just throw in two fields in to my model, but i was wondering whether
> it is possible to define a field that maps to two columns in the
> database and hides all the implementation details about precision.
>
> thanks for any input
> konstantin

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Sites module, URLs and templates

2009-10-07 Thread Joseph Wakeling

On Oct 4, 2:39 pm, Kristaps Kūlis   wrote:
> Hi!
>  You can make settings for each site easily
> first_settings.py
> from settings import *
> SITE_ID = 1
> TEMPLATE_DIRECTORIES = ( [ ] )
> [ other settings, which needs to be overrided ]
>
> you can also override urls, etc with revelant settings.

Thanks very much!  I will experiment and see what I can come up with.

Best wishes,

-- Joe
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Lighttpd Vs Apache

2009-10-07 Thread Indu

> And mod_wsgi has less performance/memory overheads than mod_python.
> One can't really compare mod_python andfastcgimemory usage as they
> have different ways of working. Performance comparisons are also
> difficult as which server is used and how it is configured can
> influence it.
>
> FWIW, in practice which hosting mechanism you use generally matters
> little to overall performance as it is usually the application or
> database which are the bottleneck and better performance in underlying
> hosting mechanism is swallowed up in that.
>
> Use which ever you are happier with as far as understanding it and
> which you find easier to configure and manage over time.
>
> Graham

I have been debating a lot on which web server to use and various
other combination for a while.  But when I saw your post here on the
django-groups, that concluded it.  Thanks for summing it up so well.
Now I can spend more time tuning my app instead of testing various
hosting combinations.

Indu

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Is django comment's honeypot really useful?

2009-10-07 Thread Kenneth Gonsalves

On Thursday 08 Oct 2009 9:32:23 am Joshua Partogi wrote:
> I want to ask for your advice here regarding the honeypot field in
> django comments. Is it really useful to prevent spam? Or should we add
> another method for spam prevention and shouldn't really rely on this
> honeypot. I currently been getting several spams on my site but I'm
> not sure whether the spammer is a bot or a human though. If it is a
> spam bot, it would be very interesting how a bot can recognize there's
> a hidden honeypot field and by-pass it. Or would a spam bot be able to
> recognize visible fields and fill in only those visible fields?
> Anybody have any advise and experience with django comments spam
> prevention?

the only time I used the honeypot I took tremendous flak from users who were 
getting caught in it - and anyway that particular app required a login for 
comments, so I safely removed it.
-- 
regards
kg
http://lawgon.livejournal.com

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: One to Many on Template UI

2009-10-07 Thread robinne

Wow, that worked, thank you! I thought I had tried everything. I was
able to loop child items on the UI template with {% for item in
mymembers.products_set.all %} ...

On Oct 6, 9:54 pm, hcarvalhoalves  wrote:
> On 7 out, 01:23, robinne  wrote:
>
> > I have my model setup with foreign key relationships. I can read one
> > table's data to the UI. But I cannot figure out how to read child
> > records onto template. I know it is (in the case of Blog, Author, and
> > Entry) b.entry_set.all(). But I don't know where this code goes. It
> > won't work in the template in a for each loop and I'm not sure how to
> > set it in the view.
>
> > my view:
>
> > mymembers = Members.objects.all()
>
> > then I return mymembers to the UI.
>
> > Please help with where I need to code the 'class'_set.all() this so
> > that I can get to child records on template UI. Thanks!
>
> No problem. You can access properties and methods from the template,
> like this:
>
> {{ b.entry_set.all }}
>
> Keep in mind that this is limited for properties and methods without
> arguments only.
> Doing something like the following doesn't work:
>
> {{ b.entry_set.filter(nickname='newbie') }}
>
> If you find coding too much logic on templates, better you process the
> values on the view
> and pass in the context, or abstract this logic in your domain model.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Is django comment's honeypot really useful?

2009-10-07 Thread Joshua Partogi

Hi all,

I want to ask for your advice here regarding the honeypot field in
django comments. Is it really useful to prevent spam? Or should we add
another method for spam prevention and shouldn't really rely on this
honeypot. I currently been getting several spams on my site but I'm
not sure whether the spammer is a bot or a human though. If it is a
spam bot, it would be very interesting how a bot can recognize there's
a hidden honeypot field and by-pass it. Or would a spam bot be able to
recognize visible fields and fill in only those visible fields?
Anybody have any advise and experience with django comments spam
prevention?

Many thanks for your advise.

regards,

-- 
Certified Scrum Master
http://twitter.com/scrum8 | http://blog.scrum8.com | http://jobs.scrum8.com

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: is this an i18n bug or a feature?

2009-10-07 Thread Kenneth Gonsalves

On Thursday 08 Oct 2009 7:05:27 am Karen Tracey wrote:
> On Wed, Oct 7, 2009 at 8:15 PM, Kenneth Gonsalves 
wrote:
> > hi,
> >
> > I recently added malayalam to an app I run - unfortunately Malayalam does
> > not
> > load. (Tamil and english work fine). I then found that django itself does
> > not
> > have malayalam. That deficiency is being rectified, but in the meantime
> > why should malayalam not load? I tried to create ~/locale/ml/LC_MESSAGES/
> > and to
> > put dummy files there. Then django timed out because it could not work
> > with blank files. I would think that this is a bug - surely django should
> > not barf
> > at using a language just because the said language is not there in django
> > itself. Should I file a ticket?
>
> It's documented behavior:
>
> http://docs.djangoproject.com/en/dev/topics/i18n/#id1

ok, thanks, good thing I did not put my foot in my mouth by filing yet another 
useless ticket.
-- 
regards
kg
http://lawgon.livejournal.com

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: is this an i18n bug or a feature?

2009-10-07 Thread Karen Tracey
On Wed, Oct 7, 2009 at 8:15 PM, Kenneth Gonsalves wrote:

>
> hi,
>
> I recently added malayalam to an app I run - unfortunately Malayalam does
> not
> load. (Tamil and english work fine). I then found that django itself does
> not
> have malayalam. That deficiency is being rectified, but in the meantime why
> should malayalam not load? I tried to create ~/locale/ml/LC_MESSAGES/ and
> to
> put dummy files there. Then django timed out because it could not work with
> blank files. I would think that this is a bug - surely django should not
> barf
> at using a language just because the said language is not there in django
> itself. Should I file a ticket?
>
>
It's documented behavior:

http://docs.djangoproject.com/en/dev/topics/i18n/#id1

Karen

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Why doesn't Django display template line number of errors?

2009-10-07 Thread Karen Tracey
On Wed, Oct 7, 2009 at 5:38 PM, NealWalters wrote:

>
> Any ideas on this question from about a month ago?
>

It was answered.  Django does display the line number, along with the line
in error and surrounding lines, in the Django debug page.  If Google App
Engine doesn't do that (don't you get Django debug pages under App Engine?),
then it's more likely you'll get a reason why or a workaround or pointer to
where to request it, in a forum that discusses Google App Engine.

Karen

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



field mapping to multiple columns?

2009-10-07 Thread akonsu

hello,

i need a datetime field with an associated precision value. the
precision shows which parts of the datatime field are used. in other
words, my datatime field can contain just a year, or a year and a
month, etc. similar to postgres' DATE_TRUNC function. i know i can
just throw in two fields in to my model, but i was wondering whether
it is possible to define a field that maps to two columns in the
database and hides all the implementation details about precision.

thanks for any input
konstantin
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: QuerySets with annonate, count() and multiple fields

2009-10-07 Thread Russell Keith-Magee

On Thu, Oct 8, 2009 at 1:43 AM, Emily Rodgers
 wrote:
>
> Hello,
>
> I am a bit stuck on something that I think ought to be really easy (so
> I am probably being really stupid!).
>
> I am trying to write a view for a model such that I can pass the view
> (via post data) a (or an unknown) number of fields of that model, and
> receive back a list of dictionaries of distinct values for those
> fields and the number of times that combination of values appears.
>
> So, suppose the model was for holding data about cars, and it had
> fields 'manufacturer', 'model', 'fuel_type', 'colour', 'n_of_doors',
> etc where the fields had appropriate field types (a mixture of
> different field types), I would want to be able to pass the view for
> example groupBy=['colour', 'fuel_type'], and it would return a dict of
> distinct colour/fuel type combinations and how many cars there are in
> the db with those combinations, eg. [{'colour': 'red', 'fuel_type:
> 'diesel', 'count': 14}, ...].
>
> To me it seems like the kind of thing you would want to use annotate
> and Count for, except Count takes one field not multiple fields.

Depending on the exact result you're looking for, this may not be a
problem. The following query may do the job:

Car.objects.values('make','model').annotate(count=Count('id'))

will give you a list of  (make, model, count) indicating how many
instances of each make-model pair there are.

The complication here is exactly what you want to count. Are you looking for:
 * The number of rows that have every make/model combination?
or
 * The number of distinct combinations for every make/model combination?

Consider the following data:

Ford | Explorer | Black
Ford | Explorer | Black
Ford | Explorer | Blue
Ford | Explorer | Red
Dodge | Charger | Red

The query I gave you will return (Ford, Explorer, 4), (Dodge, Charger,
1). However, if you want to collapse the two "black Ford Explorer"
entries and only return a count of 3, you're out of luck. For that you
need to specify multiple columns to the Count(), which Django doesn't
support. If this is what you need, you'll need to fall back on using
raw SQL.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: questions about model attribute permissions set in django admin

2009-10-07 Thread Allen

Is there a way to implement this in the django admin app?
I don't want to create a custom form or view, I want to use
the default form and view that djang admin provide.

Thanks!

On Oct 8, 2:12 am, Scott  wrote:
> I'm looking for the same kind of thing, I think you will have to
> create a custom form or view and do something like
>
> if request.user.has_perm('some_custom_perm')
>  show field
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



is this an i18n bug or a feature?

2009-10-07 Thread Kenneth Gonsalves

hi,

I recently added malayalam to an app I run - unfortunately Malayalam does not 
load. (Tamil and english work fine). I then found that django itself does not 
have malayalam. That deficiency is being rectified, but in the meantime why 
should malayalam not load? I tried to create ~/locale/ml/LC_MESSAGES/ and to 
put dummy files there. Then django timed out because it could not work with 
blank files. I would think that this is a bug - surely django should not barf 
at using a language just because the said language is not there in django 
itself. Should I file a ticket?

-- 
regards
kg
http://lawgon.livejournal.com

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ORM Cache in a standalone script

2009-10-07 Thread Karen Tracey
On Wed, Oct 7, 2009 at 7:39 PM, laligatz  wrote:

>
> Hi everybody.
>
> I'm stuck on a problem with the Django ORM.
> After a basic query like select * from table where id = 1, the result
> is still the same although i've update the row in the DB.
>
> Example:
>
> >>> Tag.objects.all()
> []
>
> >>> tag = Tag.objects.all().get()
> >>> tag
> 
>
> >>>  tag.name = 'tag11'
> >>>  tag.save()
>
> >>>  Tag.objects.all()
> []
>
> How to say to Django to make the query again ?
>
>
I cannot recreate this.  With this model:

class Tag(models.Model):
   name = models.CharField(max_length=22)
   def __unicode__(self):
  return self.name

your sequence of commands produces:

>>> from ttt.models import Tag
>>> Tag.objects.all()
[]
>>> Tag.objects.create(name='tag1')

>>> Tag.objects.all()
[]
>>> tag = Tag.objects.get()
>>> tag

>>> tag.name = 'tag11'
>>> tag.save()
>>> Tag.objects.all()
[]

Is there something you've left out of your account that might be a clue?
What's this standalone script mentioned in the subject?  Despite looking
like your sequence is from a singe python shell session, is the update being
done by a different shell/script than the query?  If so, and if you are
using MySQL/InnoDB I suspect the problem is to do its default transaction
isolation level.  But at this point point I'm leaping pretty high to a
conclusion based on guesses about what you might be doing, not what you've
actually said you are doing.

Karen

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ORM Cache in a standalone script

2009-10-07 Thread laligatz

Hi everybody.

I'm stuck on a problem with the Django ORM.
After a basic query like select * from table where id = 1, the result
is still the same although i've update the row in the DB.

Example:

>>> Tag.objects.all()
[]

>>> tag = Tag.objects.all().get()
>>> tag


>>>  tag.name = 'tag11'
>>>  tag.save()

>>>  Tag.objects.all()
[]

How to say to Django to make the query again ?

Thanks.



--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django with Cherokee web server

2009-10-07 Thread Oli Warner
>
> People quite happily run Django on memory starved VPS systems using
> Apache/mod_wsgi *with optional nginx front end* for static files.
>

Apache is woefully slow and inefficient at static serving. A static reverse
proxy is not optional for sane people.

And I'd rather just admin one server.

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django with Cherokee web server

2009-10-07 Thread Graham Dumpleton



On Oct 8, 9:38 am, Oli Warner  wrote:
> On Wed, Oct 7, 2009 at 5:34 AM, hcarvalhoalves 
> wrote:
>
> > I wanted to know if someone here on the list is using or used Cherokee
> > with Django, if there's any performance improvements over Apache +
> > mod_wsgi/mod_python (specially for concurrent requests), and if there
> > are any gotchas with Django 1.1.
>
> No gotchas with 1.1
>
> I'm not sure if it's faster with my current sites (because I never deployed
> them on Apache) but they certainly take up a lot less RAM than Apache did.
> That's really what matters to me as I'm on a VPS with limited resources. I'm
> happy.

Using Apache doesn't need to take up lots of memory. For why people
have this problem read:

http://blog.dscpl.com.au/2009/03/load-spikes-and-excessive-memory-usage.html

People quite happily run Django on memory starved VPS systems using
Apache/mod_wsgi with optional nginx front end for static files.

Graham
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django with Cherokee web server

2009-10-07 Thread Oli Warner
On Wed, Oct 7, 2009 at 5:34 AM, hcarvalhoalves wrote:

> I wanted to know if someone here on the list is using or used Cherokee
> with Django, if there's any performance improvements over Apache +
> mod_wsgi/mod_python (specially for concurrent requests), and if there
> are any gotchas with Django 1.1.
>

No gotchas with 1.1

I'm not sure if it's faster with my current sites (because I never deployed
them on Apache) but they certainly take up a lot less RAM than Apache did.
That's really what matters to me as I'm on a VPS with limited resources. I'm
happy.

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Unique Fields and form submission validation

2009-10-07 Thread Streamweaver

I found a solution off of stack overflow.  I had to bind an instance
to the form when editing. So I changed the following line:

form = ProjectForm(request.POST, instance=project)

It seems to work and is in testing.

On Oct 7, 5:40 pm, Streamweaver  wrote:
> Some more information. The view method to save the item is as follows:
>
> def update_project(request, slug):
>     '''Method for editing already existing projects.'''
>
>     project = get_object_or_404(Project, slug=slug)
>     if request.method == 'POST': # If form was submitted run it
> through.
>         form = ProjectForm(request.POST)
>         if form.is_valid():
>             form_instance = form.save(commit=False)
>             form_instance.id = project.id
>             form_instance.created_on = project.created_on
>             form_instance.save()
>             return HttpResponseRedirect(reverse('view-project', args=
> [slug]))
>     else:
>         form = ProjectForm(instance=project)
>
>     return render_with_context(request, 'project/projectedit.xhtml', {
>                                'form': form,
>                                'action': reverse('update-project',
> args=[slug]),
>                                'button': 'Update Project',
>                                'title': 'Editing Project'
>                                })
>
> On Oct 7, 5:24 pm, Streamweaver  wrote:
>
> > The title field in my model is set to unique and when I use a form to
> > edit this I get an error that an item with this value already exists.
>
> > As I understand it this is because ModelForm throws an error when I
> > call form.is_valid() and all information I can find tells me to
> > override the clean method in the form however it seems like this
> > requires me to reimplement the entire validation code again?
>
> > Is there an easier way to deal with unique text fields in form
> > validation for existing data?
>
> > Thanks in advance for any help.
>
>
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Unique Fields and form submission validation

2009-10-07 Thread Streamweaver

Some more information. The view method to save the item is as follows:

def update_project(request, slug):
'''Method for editing already existing projects.'''

project = get_object_or_404(Project, slug=slug)
if request.method == 'POST': # If form was submitted run it
through.
form = ProjectForm(request.POST)
if form.is_valid():
form_instance = form.save(commit=False)
form_instance.id = project.id
form_instance.created_on = project.created_on
form_instance.save()
return HttpResponseRedirect(reverse('view-project', args=
[slug]))
else:
form = ProjectForm(instance=project)

return render_with_context(request, 'project/projectedit.xhtml', {
   'form': form,
   'action': reverse('update-project',
args=[slug]),
   'button': 'Update Project',
   'title': 'Editing Project'
   })

On Oct 7, 5:24 pm, Streamweaver  wrote:
> The title field in my model is set to unique and when I use a form to
> edit this I get an error that an item with this value already exists.
>
> As I understand it this is because ModelForm throws an error when I
> call form.is_valid() and all information I can find tells me to
> override the clean method in the form however it seems like this
> requires me to reimplement the entire validation code again?
>
> Is there an easier way to deal with unique text fields in form
> validation for existing data?
>
> Thanks in advance for any help.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Why doesn't Django display template line number of errors?

2009-10-07 Thread NealWalters

Any ideas on this question from about a month ago?
Thanks,
Neal

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Unique Fields and form submission validation

2009-10-07 Thread Streamweaver

The title field in my model is set to unique and when I use a form to
edit this I get an error that an item with this value already exists.

As I understand it this is because ModelForm throws an error when I
call form.is_valid() and all information I can find tells me to
override the clean method in the form however it seems like this
requires me to reimplement the entire validation code again?

Is there an easier way to deal with unique text fields in form
validation for existing data?

Thanks in advance for any help.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Admin why deleting related(null=True) objects?

2009-10-07 Thread Peter Sagerson

Yes, Django always cascades deletes. There's talk about providing more  
options in a future release, but for now it's kind of a problem. I  
generally find this behavior potentially catastrophic, so I wrote an  
intermediate model base class that clears all nullable foreign keys  
before deleting an object:

http://www.djangosnippets.org/snippets/1231/

Note that this probably won't stop the admin app from warning about  
the anticipated cascade.


On Oct 7, 2009, at 6:37 AM, x_O wrote:

>
> Hi
>
> My question that I'm getting right that situation. I've two models:
>
> class First(db.models):
>second_item = models.ForeignKey('Second',null=True)
>...
>
> class Second(db.models):
>...
>
> I've both models registered in admin.py as AdminModels.
>
> Why when I'm trying to delete some object created from "Second" class
> which is RELATED to other one created from "First" class, admin is
> telling me that will remove also that "First" object (relation in
> ForeignKey is null). I understand that when there is null=False
> attribute should remove it, by why when it is null=True?
>
> In my interpretation of that should just leave First object with
> 'second_item' = None.
>
> x_O
> >


--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Models for a hockey database

2009-10-07 Thread Curt

Instead of including every player in the Game model, I would add a
field to the Player model to assign which team a player belongs to:

class Team(models.Model):
name = models.CharField(max_length=60)

class Player(models.Model):
surname = models.CharField(max_length=60)
lastname = models.CharField(max_length=60)
team = models.ForeignKey(Team)

Now you can just specify the home_team and the away_team in the Game
model without having to add every player.

For more functionality (like allowing players to switch teams) you
could use a through table that includes Player, Team, join_date and
leave_date -- The example in the docs is a good starting point for
that: http://docs.djangoproject.com/en/dev/topics/db/models/

I'm not sure how to answer a), but you can figure out b) because the
goal_scorer will be assigned to either home_players or away_players in
your original Game model, or the goal_scorer will be assigned to the
home_team or away_team in the modified models.

On Oct 5, 7:21 am, "c!w"  wrote:
> Hi,
> I trying to create a hockey database, based on Django.
> The heaviest part so long is to define the structure of my models.
> There I need some help.
> What I have so far..
>
> class Team(models.Model):
>     name = models.CharField(max_length=60)
>
> class Player(models.Model):
>     surname = models.CharField(max_length=60)
>     lastname = models.CharField(max_length=60)
>
> class Game(models.Model):
>     date_time = models.DateTimeField()
>     home_team = models.ForeignKey(Team,related_name='home_team')
>     away_team = models.ForeignKey(Team,related_name='away_team')
>     home_players = models.ManyToManyField(Player,blank=True)
>     away_players = models.ManyToManyField(Player,blank=True)
>
> class GameGoal(models.Model):
>     goal_scorer = models.ForeignKey(Player,blank=True,null=True)
>     first_assist = models.ForeignKey(Player,blank=True,null=True)
>     game = models.ForeignKey(Game)
>
> So now I have the following problems with these models.
>
> a) How can I limit the choice (in the admin page) of goal_scorer to
> Players, which are assigned to the Game?
> b) A GameGoal should be connected to the home_team or the away_team,
> how can I handle this? Add a foreignkey to Team and  limit the choice
> to the both teams?
> c) Is there a better way, to define such a case?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Models mixins/inheritance

2009-10-07 Thread Eugene Mirotin

OK, I've tried the proxy models and they solved part of my problems.
But not all.

Consider I have an auto-generated model called COmpany which I have
manually (and can then make it automatically) renamed to CompanyAuto.
I have created the Company proxy model for the CompanyAuto model and
added the __unicode__ method. Then I have registered the (new proxy)
Company model in admin and can use __unicode__ attribute as list item,
for example.

But when it comes to Many-to-One self-relations...
The Company(Auto) has the 'self'-referencing 'branch_of' attribute.
'self'==CompanyAuto, so in the company editing form I have the combo-
box containing dozens of 'CompanyAuto object' entries.
I tried to manually changed 'self' to 'Company' reference (I put the
Company definition in the same models.py file where moved the auto-
generated models), but it has no effect.

On Oct 7, 5:04 pm, Eugene Mirotin  wrote:
> I have tried it earlier and (as far as I remember) with the same
> (void) result.
> I have read more docs and proxy models seem to be the solution to my
> problem. I will give them a try later today.
>
> On Oct 7, 2:54 pm, greatlemer  wrote:
>
> > What sort of errors are you getting when you try this with the django
> > model?
>
> > Have you tried just assigning the function over the top of the
> > __unicode__ function already on Company?
>
> > i.e.
>
> > import Company
>
> > def CompanyUnicode(self):
> >     return '%s [%s]' % (self.nick, self.legal_name)
>
> > Company.__unicode__ = CompanyUnicode
>
> > __
>
> > G
>
> > On Oct 7, 12:07 pm, Eugene Mirotin  wrote:
>
> > > Let me provide more details.
>
> > > When I make simple python project with the same idea, everything works
> > > fine.
>
> > > # file test2.py
> > > class A:
> > >     b = 2
> > > # file test1.py
> > > from test2 import *
>
> > > class A(A):
> > >         a = 1
> > > # file test.py
> > > from test1 import *
>
> > > a = A()
> > > print a.b, a.a
>
> > > print A.__module__
>
> > > The output is
> > > 2 1
> > > test1
>
> > > So class A is imported from test2 to test1, then overloaded (actually
> > > extended) there, then imported to test, cool.
>
> > > When I do the same in django, everything goes wrong.
>
> > > I do import models_auto in models_business_logic, then overload the
> > > Company class, then import it in models, then import models in admin
> > > file and try
> > > print Company.__module__
> > > And this gives me the dbadm.models_auto output
>
> > > On Oct 6, 4:10 pm, Eugene Mirotin  wrote:
>
> > > > We have an existing app written in perl with Postgre as DB.
> > > > I want to add the django admin as the interface to this existing DB.
> > > > The main app is in constant development, so the DB scheme may change
> > > > in the future.
> > > > I have checked the inspectdb output and it is quite good (I do also do
> > > > some automatic fixing of the results of inspectdb, but these fixes are
> > > > minor).
> > > > So, if we would only want to have the 'dumb' db editing tool, the
> > > > auto-generated models are OK.
> > > > But what we really want is adding some additional logic (such as
> > > > __unicode__ representations and save validations). Of course, it is
> > > > unacceptable to have this code in the auto-generated file, not is is
> > > > good to always manually insert it after every db scheme update (the
> > > > models file generated by inspectdb is 1000+ lines long).
>
> > > > What I have tried looked like
> > > > - have the models_auto.py file - the inspectdb patched output
> > > > - have the models_business_logic.py module looking like
>
> > > > from models_auto import *
>
> > > > Company_ = Company
> > > > del Company
>
> > > > class Company(Company_):
> > > >     def __unicode__(self):
> > > >         return '%s [%s]' % (self.nick, self.legal_name)
>
> > > > - have the models.py file simpli importing * from models_business_logic
>
> > > > But dues to inheritance mechanism and Foreign keys (or may be dues to
> > > > some other reasons) this approach do not work.
> > > > Any ideas?
>
> > > > Thanks in advance.
>
>
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Two cache-related questions

2009-10-07 Thread kmike

> appropriate cache_prefix function

oops, key_prefix, not cache_prefix :)

On 8 окт, 01:35, kmike  wrote:
> 1. Maybe you can use django's Vary support 
> (http://docs.djangoproject.com/en/dev/topics/cache/#using-vary-headers
> ). This
> will work if you have language preferences in http headers. If you
> only set language cookie (or store language preferences in sessions)
> then you can usehttp://bitbucket.org/kmike/django-view-cache-utils/
> for that (writing appropriate cache_prefix function).
>
> 2. Functions (from the same django-view-cache-utils app) that removes
> page from cache based on page's url (and
> possibly key_prefix):
>
> http://bitbucket.org/kmike/django-view-cache-utils/src/tip/view_cache...
>
> On 8 окт, 00:11, Christophe Pettus  wrote:
>
>
>
> > Chatting with a client last night, two Django cache-related questions  
> > came up...
>
> > 1. Is there any convenient way of using the @cache_page decorator  
> > while caching separate versions by language using the Localization  
> > facilities?  It seems that it will cache the first access, and return  
> > it regardless of language.
>
> > 2. Is there a way of invalidating the cache, for example if the  
> > underlying database gets an update?
>
> > Thanks!
> > --
> > -- Christophe Pettus
> >     x...@thebuild.com
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: inline queryset dependant on runtime data

2009-10-07 Thread sico

Also, any change in the Link from_hub or to_hub will result in the
form being reloaded so no need to change the dropdown lists after
being loaded

On Oct 8, 9:22 am, sico  wrote:
> by the way, I'm using django 1.0.2   but am not against upgrading
> if it helps me solve this problem!
>
> On Oct 7, 3:36 pm,sico wrote:
>
> > Suppose I have 4 models as below:
>
> > class Hub(models.Model):
> >     name = models.CharField("Name", )
> >     something-else = models.CharField("Something", )
>
> > class HubPlug(model.Model):
> >     hub = models.ForeignKey(Hub)
> >     plug_id = models.CharField("Plug Id (A, B, C, etc)", )
>
> > class Link(model.Model):
> >     from_hub = models.ForeignKey(Hub, related_name =
> > "link_from_hub", )
> >     to_hub = models.ForeignKey(Hub, related_name = "link_to_hub", )
> >     link_type = models.CharField("Link Type", )
>
> > class LinkDetail(model.Model):
> >     link = models.ForeignKey(Link)
> >     from_plug = models.ForeignKey(HubPlug, related_name =
> > "link_from_plug", )
> >     from_plug_type = models.CharField("From Plug Type", )
> >     to_plug = models.ForeignKey(HubPlug, related_name =
> > "link_to_plug", )
> >     to_plug_type = models.CharField("To Plug Type", )
>
> > now, I have an admin form for Link that shows the Link Details as
> > Tabular Inline:
>
> > class LinkDetailInline(admin.TabularInline):
> >     model = LinkDetail
> >     extra = 3
>
> > class LinkAdmin(admin.ModelAdmin):
> >     inlines = [
> >         LinkDetailInline,
> >     ]
>
> > admin.site.register(Link, LinkAdmin)
>
> > The dropdowns for the from_plug to to_plug show all plugs and I'd like
> > them to just show the plugs for the respective from_hub/to_hub.
>
> > I'm guessing this would have to happen in the LinkAdmin class
> > somewhere, but where!!
>
> > thanks in advance,
> > Simon
>
> > p.s. would also be nice to only show those plugs that aren't in use
> > now but that should be easy once the above is sorted!
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: inline queryset dependant on runtime data

2009-10-07 Thread sico

by the way, I'm using django 1.0.2   but am not against upgrading
if it helps me solve this problem!

On Oct 7, 3:36 pm, sico  wrote:
> Suppose I have 4 models as below:
>
> class Hub(models.Model):
>     name = models.CharField("Name", )
>     something-else = models.CharField("Something", )
>
> class HubPlug(model.Model):
>     hub = models.ForeignKey(Hub)
>     plug_id = models.CharField("Plug Id (A, B, C, etc)", )
>
> class Link(model.Model):
>     from_hub = models.ForeignKey(Hub, related_name =
> "link_from_hub", )
>     to_hub = models.ForeignKey(Hub, related_name = "link_to_hub", )
>     link_type = models.CharField("Link Type", )
>
> class LinkDetail(model.Model):
>     link = models.ForeignKey(Link)
>     from_plug = models.ForeignKey(HubPlug, related_name =
> "link_from_plug", )
>     from_plug_type = models.CharField("From Plug Type", )
>     to_plug = models.ForeignKey(HubPlug, related_name =
> "link_to_plug", )
>     to_plug_type = models.CharField("To Plug Type", )
>
> now, I have an admin form for Link that shows the Link Details as
> Tabular Inline:
>
> class LinkDetailInline(admin.TabularInline):
>     model = LinkDetail
>     extra = 3
>
> class LinkAdmin(admin.ModelAdmin):
>     inlines = [
>         LinkDetailInline,
>     ]
>
> admin.site.register(Link, LinkAdmin)
>
> The dropdowns for the from_plug to to_plug show all plugs and I'd like
> them to just show the plugs for the respective from_hub/to_hub.
>
> I'm guessing this would have to happen in the LinkAdmin class
> somewhere, but where!!
>
> thanks in advance,
> Simon
>
> p.s. would also be nice to only show those plugs that aren't in use
> now but that should be easy once the above is sorted!
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Two cache-related questions

2009-10-07 Thread kmike

1. Maybe you can use django's Vary support (
http://docs.djangoproject.com/en/dev/topics/cache/#using-vary-headers
). This
will work if you have language preferences in http headers. If you
only set language cookie (or store language preferences in sessions)
then you can use http://bitbucket.org/kmike/django-view-cache-utils/
for that (writing appropriate cache_prefix function).

2. Functions (from the same django-view-cache-utils app) that removes
page from cache based on page's url (and
possibly key_prefix):

http://bitbucket.org/kmike/django-view-cache-utils/src/tip/view_cache_utils/__init__.py#cl-59

On 8 окт, 00:11, Christophe Pettus  wrote:
> Chatting with a client last night, two Django cache-related questions  
> came up...
>
> 1. Is there any convenient way of using the @cache_page decorator  
> while caching separate versions by language using the Localization  
> facilities?  It seems that it will cache the first access, and return  
> it regardless of language.
>
> 2. Is there a way of invalidating the cache, for example if the  
> underlying database gets an update?
>
> Thanks!
> --
> -- Christophe Pettus
>     x...@thebuild.com
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Two cache-related questions

2009-10-07 Thread kmike

1. Maybe you can use django's Vary support (http://
docs.djangoproject.com/en/dev/topics/cache/#using-vary-headers). This
will work if you have language preferences in http headers. If you
only set language cookie (or store language preferences in sessions)
then you can use http://bitbucket.org/kmike/django-view-cache-utils/
for that (writing appropriate cache_prefix function).

2. Function that removes page from cache based on page's url (and
possibly key_prefix):
http://bitbucket.org/kmike/django-view-cache-utils/src/tip/view_cache_utils/__init__.py

On 8 окт, 00:11, Christophe Pettus  wrote:
> Chatting with a client last night, two Django cache-related questions  
> came up...
>
> 1. Is there any convenient way of using the @cache_page decorator  
> while caching separate versions by language using the Localization  
> facilities?  It seems that it will cache the first access, and return  
> it regardless of language.
>
> 2. Is there a way of invalidating the cache, for example if the  
> underlying database gets an update?
>
> Thanks!
> --
> -- Christophe Pettus
>     x...@thebuild.com
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django comments

2009-10-07 Thread cirip

Mike,

I find it very limiting that by default comments can be made on
database objects only. Another limitation that I hit is that I can't
comment on comment. It is failing at least for me. I will probably
implement whole comments myself.

Thanks again,

Tomas

On Oct 6, 5:43 pm, kmike  wrote:
> It seems thatdjango'scommentssystem isn't exactly what your want.
> It is quity easy to write your specialisedcommentsapp, one solution
> is to just write your own.
>
> Second solution solution is:
>
> 1. Attachcommentsto your page model, not paragraph.
> 2. Add paragraph_id field to comment model.
> 3. Customizecommentsform to include (hidden?) paragraph_id field
> 4. Use {% regroup %} template tag in templates for comment rendering.
> 5. Write your own render_comment_form template tag which accepts
> additional paragraph_id parameter and constructs form taking this
> parameter in account. If it's not sufficient, write your versions of
> necessery template tags (or just don't use them, theay are not
> required forcommentsapp to work).
>
> On 6 окт, 00:38, cirip  wrote:
>
> > Mike,
>
> > Thanks. Well I understand that I can add extra field. That's not my
> > problem. My problem is that I want to be able to add comment without
> > having to create an instance of the object thatcommentsrefers to.
> > For example for render the form I shall use:
>
> > {% get_comment_count for config.commenttarget 'paragraph_14' as
> > comment_count %}
>
> > Model config.commenttarget exists, but there is no data in that table.
> > However, I can readcommentsand get count etc.
>
> > When it comes to rendering entry form
>
> > {% render_comment_form for paragraph %}
>
> > I need to create paragraph object to render the form. I don't wan to
> > create paragraph object in the database for each paragraph that I want
> > to comment on. I mean I could try to create object paragraph and never
> > persist it and it all might magically work.
>
> > All I want iscommentswithout any referential integrity with just one
> > extra field - paragraph id that I could use to querycommentsfor that
> > particular paragraph.
>
> > Thanks again,
>
> > Tomas
>
> > On Oct 3, 11:28 am, kmike  wrote:
>
> > > If you want additional field (paragraph_id) in Comment model you can
> > > create your own model as decribed here:
>
> > >http://docs.djangoproject.com/en/dev/ref/contrib/comments/custom/#ref...
>
> > > On 3 окт, 01:46, cirip  wrote:
>
> > > > Hi,
>
> > > > I am just reading aboutdjangocommentsframework that I planned to
> > > > use.
>
> > > > As I learned so far you have to have object to whichcommentsbelong
> > > > in the database as well. Let's say I just want to havecomments
> > > > related to some paragraph on my page without having to create record
> > > > for each paragraph that I want to comment on and I would like to use
> > > > paragraph id as the key to identify thecomments.
>
> > > > Thanks,
>
> > > > Tomas
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Getting former value of altered field when saving model

2009-10-07 Thread Nan


It should work in pre_save, but by the time you reach post_save, the
database ID will be associated with the new values.

On Oct 7, 1:32 pm, Aaron  wrote:
> On Oct 7, 2:14 pm, Nan  wrote:
>
> > class Foo(models.Model):
> > bar = models.IntegerField()
>
> > def save(self, force_insert=False, force_update=False):
> > if self.id:
> > # this is an update rather than a new instance
> > old = Foo.objects.get(pk=self.id)
> > # DO STUFF
> > super(Foo, self).save(force_insert, force_update)
>
> Oh, so I'm actually able to get the old value of the field after all:
>
> def save(self, force_insert=False, force_update=False):
> if self.id:
> # this is an update rather than a new instance
> old = Foo.objects.get(pk=self.id)
>
> old_field =  old.field_that_i_want
> new_field = self.field_that_i_want
>
> # Do something with old_field and new_field
>
> super(Foo, self).save(force_insert, force_update)
>
> Thanks. :)
>
> Would this also work in pre_save or post_save signals, or only in the
> model's save method?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Nullable GenericForeignKey?

2009-10-07 Thread ringemup

When I try to set null=True on a GenericForeignKey field, I get a
TypeError: __init__() got an unexpected keyword argument 'null'.  Does
this mean that GenericForeignKeys can't be null, or does it mean that
their nullability is automatically determined by the nullability of
their content_type and object_id fields?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: filter to wrap content in html tags

2009-10-07 Thread kelley....@gmail.com

The answer is at 
http://groups.google.com/group/django-users/browse_thread/thread/5d5a6c5b511ca96
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: questions about model attribute permissions set in django admin

2009-10-07 Thread Scott

I'm looking for the same kind of thing, I think you will have to
create a custom form or view and do something like

if request.user.has_perm('some_custom_perm')
 show field

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Two cache-related questions

2009-10-07 Thread Christophe Pettus

Chatting with a client last night, two Django cache-related questions  
came up...

1. Is there any convenient way of using the @cache_page decorator  
while caching separate versions by language using the Localization  
facilities?  It seems that it will cache the first access, and return  
it regardless of language.

2. Is there a way of invalidating the cache, for example if the  
underlying database gets an update?

Thanks!
--
-- Christophe Pettus
x...@thebuild.com


--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



filter to wrap content in html tags

2009-10-07 Thread kelley....@gmail.com

INTRODUCTION.  I wrote a filter to wrap content in  tags, with
different classes for different types of content.  (It's to code
command/response dialogues in the R language.)  I've got the filter
working fine, but the results are being altered to change the "<" into
"" and so forth.  I guess that's a protection method.

QUESTION: is there a way I can prevent this escaping?  Put another
way, how can I make a filter output HTML code, so I can use CSS to
style things?

BACKGROUND: I am putting

{{ note.content|Rfmt }}

in my template.  The filter is as below (you'll see that R uses ">" to
preface commands and [#] to preface responses.).

import re
from django import template
from django.template.defaultfilters import stringfilter
register = template.Library()
c = re.compile('^>(?P.*)')
r = re.compile('^\[(?P.*)')


# 
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#howto-custom-template-tags
@register.filter
@stringfilter
def Rfmt(value):
""" converts multi-line string into code and response
fragments
>> print(Rfmt("> a<-3\n[1] 3\n> pi\n[1]
3.141"))
"""
lines = value.split('\n')
for i, line in enumerate(lines):
lines[i] = c.sub('\g<1>', line)
lines[i] = r.sub('[\g<1>', lines[i])
return "\n".join(lines)
Rfmt.is_safe = True



--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



QuerySets with annonate, count() and multiple fields

2009-10-07 Thread Emily Rodgers

Hello,

I am a bit stuck on something that I think ought to be really easy (so
I am probably being really stupid!).

I am trying to write a view for a model such that I can pass the view
(via post data) a (or an unknown) number of fields of that model, and
receive back a list of dictionaries of distinct values for those
fields and the number of times that combination of values appears.

So, suppose the model was for holding data about cars, and it had
fields 'manufacturer', 'model', 'fuel_type', 'colour', 'n_of_doors',
etc where the fields had appropriate field types (a mixture of
different field types), I would want to be able to pass the view for
example groupBy=['colour', 'fuel_type'], and it would return a dict of
distinct colour/fuel type combinations and how many cars there are in
the db with those combinations, eg. [{'colour': 'red', 'fuel_type:
'diesel', 'count': 14}, ...].

To me it seems like the kind of thing you would want to use annotate
and Count for, except Count takes one field not multiple fields.

I tried using values() to limit the fields, then python to do the
counting / distinct bit, but it is annoying because I want to be able
to tell it to return the unicode values for foreign keys etc. rather
than ids that would then need to be looked up. Also it is way too
slow.

I am trying to figure a way to do this that is reasonably fast because
I am trying to filter a lot of data. Am I missing something? I haven't
been using python / django much lately so I am probably thinking the
wrong way!

Any help would be appreciated :)

Em

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Year/month archive help

2009-10-07 Thread icrismariu

Hello, i'm new to Django and started an application, i did the models,
views, templates, but i want to add some kind of archive to the bottom
of the page, something like this 
http://www.flickr.com/photos/ionutgabriel/3990015411/.

My model looks like this:

class Post(models.Model):
titlu = models.CharField(max_length=45)
continut = models.TextField()
imagine = models.CharField(max_length=150)
data = models.DateTimeField()
modificat = models.DateTimeField (blank = True, null = True)

I know i have to loop trough the model and on the "data" field...i've
searched all day for a solution, but didn't find anything.

I want to show the year, and the months, and only the months who have
entries to be links so i can redirect users to another view where they
can see only the posts from that month.

How can i do this?

Thank you for you're help!

p.s. sorry for my English

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Getting former value of altered field when saving model

2009-10-07 Thread Aaron

On Oct 7, 2:14 pm, Nan  wrote:
> class Foo(models.Model):
>     bar = models.IntegerField()
>
>     def save(self, force_insert=False, force_update=False):
>         if self.id:
>             # this is an update rather than a new instance
>             old = Foo.objects.get(pk=self.id)
>             # DO STUFF
>         super(Foo, self).save(force_insert, force_update)

Oh, so I'm actually able to get the old value of the field after all:

def save(self, force_insert=False, force_update=False):
if self.id:
# this is an update rather than a new instance
old = Foo.objects.get(pk=self.id)

old_field =  old.field_that_i_want
new_field = self.field_that_i_want

# Do something with old_field and new_field

super(Foo, self).save(force_insert, force_update)

Thanks. :)

Would this also work in pre_save or post_save signals, or only in the
model's save method?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: where can I find email alert functionality

2009-10-07 Thread Fred Chevitarese
I'm looking for this too, but had no success... I'll have to made your own
...

http://chevitarese.wordpress.com
Fred Chevitarese - GNU/Linux


2009/10/6 Norman 

>
> hello,
>
> I look for  email alert functionality, where readers sign up to get
> notifications when news happens. But I can't find any suitable django
> app.
>
> So where can I find something like this?
>
> Any snippet or source code?
>
> regards, nomanek
> >
>

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Getting former value of altered field when saving model

2009-10-07 Thread Nan

class Foo(models.Model):
bar = models.IntegerField()

def save(self, force_insert=False, force_update=False):
if self.id:
# this is an update rather than a new instance
old = Foo.objects.get(pk=self.id)
# DO STUFF
super(Foo, self).save(force_insert, force_update)


On Oct 7, 1:01 pm, Aaron  wrote:
> I have a model with a particular field I'm interested in. If that
> field is altered, I want to be able to access the former value of that
> field (as well as the new value).
>
> I've looked at pre_save() signals, models, and fields, and it seems
> that I am only able to access the current (new) value of the field;
> it's old value is lost.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django and ZSI

2009-10-07 Thread Fred Chevitarese
Hello all!! I've been looking for a while in this group, then i find this
message...
Anyone has an example of python/Django with ZSI, suds, Soappy or another
that exists ?
I'm looking for anything but the documentation is not good...

If anyone has a piece of code to take a look it would be appreciated...

Thanks in advance ;)

http://chevitarese.wordpress.com
Fred Chevitarese - GNU/Linux


2009/10/7 Janusz 

>
> HI,
> I have an additional question to this topic: how exactly do you deploy
> ZSI-generated web services from within Django?
> BR/Janusz
>
> On Sep 2, 2:37 am, Julián C. Pérez  wrote:
> > Thanks
> >
> > On Aug 31, 3:22 pm, Antoni Aloy  wrote:
> >
> >
> >
> > > 2009/8/31 Julián C. Pérez :
> >
> > > > Anyone has experience with using web services inDjango??
> > > > I mean, not necessarily withZSIbut others methods...
> >
> > > Yes, we have many of the working. But this is no aDjangoissue is
> > > more a Python programming one. You can access to Soap web services
> > > usingZSI, SUDS, Soappy or whatever you like to use.
> >
> > > Isolate the web service client and use the parts you need. We have
> > > worked withZSImainly, but actually we're moving to Suds.
> >
> > > To act a a server we prefer to simplify and we're using xml over http
> > > or REST services. Both live perfectly withDjango.
> >
> > > --
> > > Antoni Aloy López
> > > Blog:http://trespams.com
> > > Site:http://apsl.net
>
> >
>

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ORM

2009-10-07 Thread Christophe Pettus


On Oct 7, 2009, at 2:30 AM, Geobase Isoscale wrote:
>  I intend to write ORM code that will create views and triggers in  
> the database? Which parts of the source code should I alter?

Django can work just fine with views and triggers, but the Django ORM  
layer will not create them for you.  Views tend to be extremely  
database-specific, and triggers even more so.

In the case of views, you can create them using the database's native  
view creation mechanism, and then set up a Django model to access  
them, just as if they were a table (in this case, you would not use  
syncdb to create the tables).  If you are using PostgreSQL, you can  
even set them up to be updatable using the rules system.  As long as  
they can be used just like a table with standard SQL SELECT / INSERT /  
DELETE, Django should be perfectly happy to access them.

In the case of triggers, there's no reason that a database that Django  
is accessing cannot use triggers.  The only thing to keep in mind is  
that if a trigger modifies a database row that also exists in memory  
as a model object instance, nothing will cause the model object  
instance to automatically reflect the changes in the database row, so  
you might have "cache" consistency problems.

So, if what you are asking is, "Can I use the Django ORM to access a  
database in which I have created views and triggers," the answer is  
"yes, provided you understand potential interactions."  If the  
question is, "Can the Django ORM create views and triggers in the  
database through its API," the answer is no.
--
-- Christophe Pettus
x...@thebuild.com


--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Getting former value of altered field when saving model

2009-10-07 Thread Aaron

I have a model with a particular field I'm interested in. If that
field is altered, I want to be able to access the former value of that
field (as well as the new value).

I've looked at pre_save() signals, models, and fields, and it seems
that I am only able to access the current (new) value of the field;
it's old value is lost.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django with Cherokee web server

2009-10-07 Thread Leonel Nunez

> Thanks for the advice, but I already know how to optimize django apps
> (documentation covers this well), so I'm not seeking advice on this.
> Neither I'm willing to use Cherokee so I get a magic performance boost
> for my app alone (while it is indeed faster than Apache for serving
> static content).
>
> Instead, I'm looking for advice from someone who already deployed
> Django with Cherokee.


I use   Django + cherokee.

Works great, you can use for load balancing your django apps, or use as a
proxy, or just server static content


saludos

Leonel





--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django with Cherokee web server

2009-10-07 Thread hcarvalhoalves

Thanks for the advice, but I already know how to optimize django apps
(documentation covers this well), so I'm not seeking advice on this.
Neither I'm willing to use Cherokee so I get a magic performance boost
for my app alone (while it is indeed faster than Apache for serving
static content).

Instead, I'm looking for advice from someone who already deployed
Django with Cherokee.

On Oct 7, 2:41 am, Graham Dumpleton 
wrote:
> On Oct 7, 3:34 pm, hcarvalhoalves  wrote:
>
>
>
> > I recently found this web server (http://www.cherokee-project.com/)
> > that claims to be "the fastest web server". I'm not sure that holds
> > true for *CGI, but at least for static content they have some
> > impressive benchmarks. Despite the claimings, it's an interesting
> > alternative for what it supports out-of-the-box alone: administrative
> > interface, simpler configuration, transparent restart, load balancer,
> > db balancer, virtual hosts, TLS, and some other cool, easy to setup
> > features.
>
> > Setting it up for working with Django is a breeze (http://www.cherokee-
> > project.com/doc/cookbook_django.html) and I already did some tests,
> > now I'm considering trying it in production.
>
> > I wanted to know if someone here on the list is using or used Cherokee
> > with Django, if there's any performance improvements over Apache +
> > mod_wsgi/mod_python (specially for concurrent requests), and if there
> > are any gotchas with Django 1.1.
>
> Repeat after me 100 times. The bottleneck is not the web server, it is
> your application logic, use of caching and the database.
>
> Chase the mythical fastest web server in the world, of which there are
> many to choose from based on claims they all make, but you will be
> wasting your time. If you want better performance, you are better off
> focusing on addressing the performance problems your own application
> and the database introduces.
>
> So, just use whatever web server you have a tendency to like, that you
> find easy to configure and maintain, and which you perceive as being
> stable. After all, you don't want to have to tangle with the web
> server, you will need all the time you have to make your own
> application work better.
>
> Graham
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



questions about model attribute permissions set in django admin

2009-10-07 Thread Allen

Hi, all:

  I am working on a project with django, I have encounter a problem
and searched it in google, but didn't find any solution:

  I have two users can login django admin, and I have a model with
some attributes.

  one of the users is site admin and the other is a normal users, both
of them can login the django admin site and can edit the model
instance.

  I want to implement this feature: some of attributes of the model
instance are editable in the django admin for admin user, but not
editable for the normal user. I have tried to set the attributes with
editable=False while define the model, but with this, both of admin
and normal user can not edit these attributes.

  Is there a way to implement this? if there is, how to do this step
by step?

 Anybody who can help me? with detail instructions?

 Thanks!

  Best Regards!

Allen

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django and ZSI

2009-10-07 Thread Janusz

HI,
I have an additional question to this topic: how exactly do you deploy
ZSI-generated web services from within Django?
BR/Janusz

On Sep 2, 2:37 am, Julián C. Pérez  wrote:
> Thanks
>
> On Aug 31, 3:22 pm, Antoni Aloy  wrote:
>
>
>
> > 2009/8/31 Julián C. Pérez :
>
> > > Anyone has experience with using web services inDjango??
> > > I mean, not necessarily withZSIbut others methods...
>
> > Yes, we have many of the working. But this is no aDjangoissue is
> > more a Python programming one. You can access to Soap web services
> > usingZSI, SUDS, Soappy or whatever you like to use.
>
> > Isolate the web service client and use the parts you need. We have
> > worked withZSImainly, but actually we're moving to Suds.
>
> > To act a a server we prefer to simplify and we're using xml over http
> > or REST services. Both live perfectly withDjango.
>
> > --
> > Antoni Aloy López
> > Blog:http://trespams.com
> > Site:http://apsl.net

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Models mixins/inheritance

2009-10-07 Thread Eugene Mirotin

I have tried it earlier and (as far as I remember) with the same
(void) result.
I have read more docs and proxy models seem to be the solution to my
problem. I will give them a try later today.

On Oct 7, 2:54 pm, greatlemer  wrote:
> What sort of errors are you getting when you try this with the django
> model?
>
> Have you tried just assigning the function over the top of the
> __unicode__ function already on Company?
>
> i.e.
>
> import Company
>
> def CompanyUnicode(self):
>     return '%s [%s]' % (self.nick, self.legal_name)
>
> Company.__unicode__ = CompanyUnicode
>
> __
>
> G
>
> On Oct 7, 12:07 pm, Eugene Mirotin  wrote:
>
> > Let me provide more details.
>
> > When I make simple python project with the same idea, everything works
> > fine.
>
> > # file test2.py
> > class A:
> >     b = 2
> > # file test1.py
> > from test2 import *
>
> > class A(A):
> >         a = 1
> > # file test.py
> > from test1 import *
>
> > a = A()
> > print a.b, a.a
>
> > print A.__module__
>
> > The output is
> > 2 1
> > test1
>
> > So class A is imported from test2 to test1, then overloaded (actually
> > extended) there, then imported to test, cool.
>
> > When I do the same in django, everything goes wrong.
>
> > I do import models_auto in models_business_logic, then overload the
> > Company class, then import it in models, then import models in admin
> > file and try
> > print Company.__module__
> > And this gives me the dbadm.models_auto output
>
> > On Oct 6, 4:10 pm, Eugene Mirotin  wrote:
>
> > > We have an existing app written in perl with Postgre as DB.
> > > I want to add the django admin as the interface to this existing DB.
> > > The main app is in constant development, so the DB scheme may change
> > > in the future.
> > > I have checked the inspectdb output and it is quite good (I do also do
> > > some automatic fixing of the results of inspectdb, but these fixes are
> > > minor).
> > > So, if we would only want to have the 'dumb' db editing tool, the
> > > auto-generated models are OK.
> > > But what we really want is adding some additional logic (such as
> > > __unicode__ representations and save validations). Of course, it is
> > > unacceptable to have this code in the auto-generated file, not is is
> > > good to always manually insert it after every db scheme update (the
> > > models file generated by inspectdb is 1000+ lines long).
>
> > > What I have tried looked like
> > > - have the models_auto.py file - the inspectdb patched output
> > > - have the models_business_logic.py module looking like
>
> > > from models_auto import *
>
> > > Company_ = Company
> > > del Company
>
> > > class Company(Company_):
> > >     def __unicode__(self):
> > >         return '%s [%s]' % (self.nick, self.legal_name)
>
> > > - have the models.py file simpli importing * from models_business_logic
>
> > > But dues to inheritance mechanism and Foreign keys (or may be dues to
> > > some other reasons) this approach do not work.
> > > Any ideas?
>
> > > Thanks in advance.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Redirects and nested URLs

2009-10-07 Thread Aaron

Is the redirects app able to handle nested URLs? For example, if I
have /foo/, and I also have /foo/bar/, would adding a redirect from /
foo/ to /baz/ also create a redirect from /foo/bar/ to /baz/bar/?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Admin why deleting related(null=True) objects?

2009-10-07 Thread x_O

Hi

My question that I'm getting right that situation. I've two models:

class First(db.models):
second_item = models.ForeignKey('Second',null=True)
...

class Second(db.models):
...

I've both models registered in admin.py as AdminModels.

Why when I'm trying to delete some object created from "Second" class
which is RELATED to other one created from "First" class, admin is
telling me that will remove also that "First" object (relation in
ForeignKey is null). I understand that when there is null=False
attribute should remove it, by why when it is null=True?

In my interpretation of that should just leave First object with
'second_item' = None.

x_O
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Add some fields on form.save()

2009-10-07 Thread Bogdan I. Bursuc

If you want to set the status field on the model after you save the
form, you can do something like this:
msg_instance = form.save(commit=False)
msg_instance.status = 'F'
msg_instance.save() # don't forget the save, because the form didn't
# save the model

On Wed, 2009-10-07 at 06:14 -0700, valler wrote:
> Hello.
> 
> I can't understand how I can add some extra fields on form saving.
> 
> Here is a simple example:
> 
> class Msg(models.Model):
>   title = models.CharField(max_length=30)
>   message = models.CharField(max_length=100)
>   status = models.CharrField(max_length=1,null=True,blank=True)
> 
> class MsgForm(ModelForm):
>   class Meta:
> model = Msg
> exclude = ('status') ## I don't want users to see it in html form
> ##
> 
> ...
> status = 'F' ## for example
> if request.method == 'POST':
>   form = msgForm(request.POST)
>   if form.is_valid:
> form.save() 
> 
> How can i set status here? If i set form = msgForm(request.POST,
> initial={status:'F'}) - this does nothing.
> 
> > 


--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Add some fields on form.save()

2009-10-07 Thread valler

Hello.

I can't understand how I can add some extra fields on form saving.

Here is a simple example:

class Msg(models.Model):
  title = models.CharField(max_length=30)
  message = models.CharField(max_length=100)
  status = models.CharrField(max_length=1,null=True,blank=True)

class MsgForm(ModelForm):
  class Meta:
model = Msg
exclude = ('status') ## I don't want users to see it in html form
##

...
status = 'F' ## for example
if request.method == 'POST':
  form = msgForm(request.POST)
  if form.is_valid:
form.save() 

How can i set status here? If i set form = msgForm(request.POST,
initial={status:'F'}) - this does nothing.

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ORM

2009-10-07 Thread Jani Tiainen

Geobase Isoscale kirjoitti:
> I have to live with this reality, maybe in future we might  develop a 
> code to extend Django to support views and triiggers. 

I don't get the use case here. What is this need for adding views and 
triggers? What purpose they serve for ORM?

For database they're pretty handy to do business logic if there is data 
incoming form external resources that are not passed through ORM that 
can take care of all that mess but this can already be done with Django.

There is (standard) way to add arbitary SQL scripts that are ran after 
django tables and such are generated or it can be done quite easily 
manually.

Could you provide some examples what you're trying to achieve to shed 
some light here..?

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Getting model's ID in save() method

2009-10-07 Thread Aaron

On Oct 6, 4:48 pm, Karen Tracey  wrote:
> I showed it from the shell because that's easiest to demonstrate.  But it
> also works for the model you have included here even from admin.  If it's
> not working for the model you actually have then it is due to some
> difference between what you have posted and what you are actually using.
>
> Simplifying is good, so long as you haven't simplified to the point where
> the error no longer appears, which is what you seem to have done in this
> case.  You might try starting from the simplified case and adding back in
> the things you removed in simplification to figure out which one causes a
> problem.  That would be a hint.

In any case, my model is working now. I think I just had to rebuild
the database. Thank you.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ORM

2009-10-07 Thread Geobase Isoscale
I have to live with this reality, maybe in future we might  develop a code
to extend Django to support views and triiggers.

Many Thanks

Isoscale

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Models mixins/inheritance

2009-10-07 Thread greatlemer

What sort of errors are you getting when you try this with the django
model?

Have you tried just assigning the function over the top of the
__unicode__ function already on Company?

i.e.

import Company

def CompanyUnicode(self):
return '%s [%s]' % (self.nick, self.legal_name)

Company.__unicode__ = CompanyUnicode

__

G

On Oct 7, 12:07 pm, Eugene Mirotin  wrote:
> Let me provide more details.
>
> When I make simple python project with the same idea, everything works
> fine.
>
> # file test2.py
> class A:
>     b = 2
> # file test1.py
> from test2 import *
>
> class A(A):
>         a = 1
> # file test.py
> from test1 import *
>
> a = A()
> print a.b, a.a
>
> print A.__module__
>
> The output is
> 2 1
> test1
>
> So class A is imported from test2 to test1, then overloaded (actually
> extended) there, then imported to test, cool.
>
> When I do the same in django, everything goes wrong.
>
> I do import models_auto in models_business_logic, then overload the
> Company class, then import it in models, then import models in admin
> file and try
> print Company.__module__
> And this gives me the dbadm.models_auto output
>
> On Oct 6, 4:10 pm, Eugene Mirotin  wrote:
>
>
>
> > We have an existing app written in perl with Postgre as DB.
> > I want to add the django admin as the interface to this existing DB.
> > The main app is in constant development, so the DB scheme may change
> > in the future.
> > I have checked the inspectdb output and it is quite good (I do also do
> > some automatic fixing of the results of inspectdb, but these fixes are
> > minor).
> > So, if we would only want to have the 'dumb' db editing tool, the
> > auto-generated models are OK.
> > But what we really want is adding some additional logic (such as
> > __unicode__ representations and save validations). Of course, it is
> > unacceptable to have this code in the auto-generated file, not is is
> > good to always manually insert it after every db scheme update (the
> > models file generated by inspectdb is 1000+ lines long).
>
> > What I have tried looked like
> > - have the models_auto.py file - the inspectdb patched output
> > - have the models_business_logic.py module looking like
>
> > from models_auto import *
>
> > Company_ = Company
> > del Company
>
> > class Company(Company_):
> >     def __unicode__(self):
> >         return '%s [%s]' % (self.nick, self.legal_name)
>
> > - have the models.py file simpli importing * from models_business_logic
>
> > But dues to inheritance mechanism and Foreign keys (or may be dues to
> > some other reasons) this approach do not work.
> > Any ideas?
>
> > Thanks in advance.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Models mixins/inheritance

2009-10-07 Thread Eugene Mirotin

Let me provide more details.

When I make simple python project with the same idea, everything works
fine.

# file test2.py
class A:
b = 2
# file test1.py
from test2 import *

class A(A):
a = 1
# file test.py
from test1 import *

a = A()
print a.b, a.a

print A.__module__


The output is
2 1
test1

So class A is imported from test2 to test1, then overloaded (actually
extended) there, then imported to test, cool.

When I do the same in django, everything goes wrong.

I do import models_auto in models_business_logic, then overload the
Company class, then import it in models, then import models in admin
file and try
print Company.__module__
And this gives me the dbadm.models_auto output


On Oct 6, 4:10 pm, Eugene Mirotin  wrote:
> We have an existing app written in perl with Postgre as DB.
> I want to add the django admin as the interface to this existing DB.
> The main app is in constant development, so the DB scheme may change
> in the future.
> I have checked the inspectdb output and it is quite good (I do also do
> some automatic fixing of the results of inspectdb, but these fixes are
> minor).
> So, if we would only want to have the 'dumb' db editing tool, the
> auto-generated models are OK.
> But what we really want is adding some additional logic (such as
> __unicode__ representations and save validations). Of course, it is
> unacceptable to have this code in the auto-generated file, not is is
> good to always manually insert it after every db scheme update (the
> models file generated by inspectdb is 1000+ lines long).
>
> What I have tried looked like
> - have the models_auto.py file - the inspectdb patched output
> - have the models_business_logic.py module looking like
>
> from models_auto import *
>
> Company_ = Company
> del Company
>
> class Company(Company_):
>     def __unicode__(self):
>         return '%s [%s]' % (self.nick, self.legal_name)
>
> - have the models.py file simpli importing * from models_business_logic
>
> But dues to inheritance mechanism and Foreign keys (or may be dues to
> some other reasons) this approach do not work.
> Any ideas?
>
> Thanks in advance.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ORM

2009-10-07 Thread Russell Keith-Magee

On Wed, Oct 7, 2009 at 5:30 PM, Geobase Isoscale  wrote:
> Hi Everyone,
>  I intend to write ORM code that will create views and triggers in the
> database? Which parts of the source code should I alter?

This is the third time you've asked the same question in less than a
week. I answered the first time [1]; Daniel Roseman answered the
second time [2].

[1] 
http://groups.google.com/group/django-users/browse_thread/thread/88d08478478199b6
[2] 
http://groups.google.com/group/django-users/browse_thread/thread/dd1c601dd7f5e1d1

The answer hasn't changed. Django's ORM doesn't provide support for
views and triggers.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ORM

2009-10-07 Thread Jani Tiainen

Geobase Isoscale kirjoitti:
> Hi Everyone, 
> 
>  I intend to write ORM code that will create views and triggers in the 
> database? Which parts of the source code should I alter?

None...

There already exists mechanism to run arbitary SQL after syncdb...

Or did you meant something else since I'm not sure what you mean by 
"views" and "triggers" and how they are related to ORM...

-- 
Jani Tiainen

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ORM

2009-10-07 Thread Geobase Isoscale
Hi Everyone,
 I intend to write ORM code that will create views and triggers in the
database? Which parts of the source code should I alter?

Many Thanks

Isoscale

--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Unhandled IntegrityError caused by setting unique_together over DateField and SlugField

2009-10-07 Thread Michiel

Hi,

Yes, I am adding instances via the admin.

I suspected the field not being on the form was the cause of there
being no nice error message. Thanks for confirming this.

I guess to best (and only?) way to deal with this now is to add my own
validation to the form clean() method and inform the user myself?

Michiel

On Oct 6, 6:16 pm, Karen Tracey  wrote:
> On Tue, Oct 6, 2009 at 11:44 AM, Michiel wrote:
>
>
>
>
>
> > Hi,
>
> > I'm getting an unhandled IntegrityError after setting a
> > unique_together over a DateField and a SlugField, is that considered a
> > bug or not?
>
> > I expected it to show a nice error message informing the user that he
> > should pick something else for either Date or Slug. I does do that
> > when I set the unique_together over the 'title' and the 'title_slug'
> > SlugField.
>
> > DateField is auto_now_add=True, could that have something to do with
> > it? Also: I'm using sqlite3.
>
> (I assume you are talking about adding instances via the admin?)
>
> Yes, auto_now_add has something to do with it.  auto_now_add=True means the
> value of the field is not present in the form. Uniqueness checking is done
> during form validation, and only checks values that are present in the
> form.  Thus if a field value not present in the form is going to cause a
> uniqueness violation it won't be detected by the unique check.
>
> Karen
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Getting django working on jython/modjy/jetty

2009-10-07 Thread Arto Vuori

Solved. Passing the webapps directory of Jetty to the python.path via
modjy servlet parameters in WEB-INF/web.xml helped.
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---