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



inline queryset dependant on runtime data

2009-10-06 Thread sico

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



alternative to using index number to refer to inline admin formsets in template?

2009-08-30 Thread sico

Hey,

I can get to the inline_admin_formset by indexing the
inline_admin_formsets variable

e.g.

{{ inline_admin_formsets.0.formset }}

is there an alternative to use the index number for picking the
formset??  I've tried the model name but it doesn't seem to work...
any suggestions??

thanks,
Simon




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



multiple admin interfaces for a single model

2009-08-30 Thread sico

Hey,

Is it at all possible to have more than one admin interface for one
model?

I'd like to have a simple view that just edits the one model fields,
and another (maybe more) that edit the model, plus several inline
associated models.

I can get this to work by having separate AdminSites, is this the only
way?  It would be nice if they could all be in the same site.

Regards,
Simon
--~--~-~--~~~---~--~~
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: formset consisting of multiple models/forms

2009-08-03 Thread sico

Hi,

Just to clarify here, I really want to keep using forms.ModelForm to
avoid having to redefine any data types and labels.  I could create a
single form that has all the fields I want and use that in a formset.
But then I have to duplicate the field/model definitions and also
handle the binding of the data from the form to the model.

thanks,
Simon

On Aug 4, 1:12 pm, sico  wrote:
> Hi,
>
> I have several models linked OneToOne by their primary keys.
>
> I can make a single view that has a form for each model and allow the
> user to edit data from the each of the models in a single screen (as
> if it were all stored in a single table/model)
>
> I'd like to be able to do this in a grid, with a single row linking to
> data from several different models.
>
> From what I can see, I could have several formsets but this would give
> me a separate grid for each model.  I suppose I could position them
> next to each so it looks like a single grid, but that sounds
> troublesome!
>
> Can I have a single formset spanning multiple forms/models ??
>
> thanks,
> Simon
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



formset consisting of multiple models/forms

2009-08-03 Thread sico

Hi,

I have several models linked OneToOne by their primary keys.

I can make a single view that has a form for each model and allow the
user to edit data from the each of the models in a single screen (as
if it were all stored in a single table/model)

I'd like to be able to do this in a grid, with a single row linking to
data from several different models.

>From what I can see, I could have several formsets but this would give
me a separate grid for each model.  I suppose I could position them
next to each so it looks like a single grid, but that sounds
troublesome!

Can I have a single formset spanning multiple forms/models ??

thanks,
Simon
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



multiple admin forms for one model

2009-07-30 Thread sico

Is it possible to have more than one admin interface for a form in the
same AdminSite ?

I'd like to have an admin form for just editing the model, and another
one for editing the model and some sub-records.  Is this possible
within the same AdminSite ??

You're not allowed to do more than one:

admin.site.register(MyModel, )

So it doesn't look like it will and that I will need to have a
different Admin Site, but this becomes cumbersome as I'd quite like to
have several different interfaces here.

I suppose I can do a view for each one here, but then I have to
duplicate a lot of functionality that is already in the admin site...
e.g. displaying the label, widget, and errors, handling adding, saving
etc, and writing to the admin log.

thanks,
Simon
--~--~-~--~~~---~--~~
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: view/form with fields from multiple models

2009-07-30 Thread sico

Hey,

I've been a little distracted but I'm back on to this now...

Thanks for the information, I'm going to try it out now (assuming no
more interruptions!) and I'll  get back to you on how I get on...



On Jul 24, 8:55 pm, Matthias Kestenholz
 wrote:
> On Fri, Jul 24, 2009 at 10:46 AM, Benjamin  Wohlwend 
> wrote:
>
> > On Jul 24, 10:37 am, Benjamin  Wohlwend  wrote:
>
> >> if all(f.is_valid() for f in (form1, form2, form3)):
> >>     # ok, save
>
> > Oops, forgot to mention that I had to implement my own version of all
> > (), which doesn't short cut:
>
> > def really_all(iter):
> >    all_true = True
> >    for val in iter:
> >        if not val:
> >            all_true = False
> >    return all_true
>
> There is a function in Django proper which does exactly that:
> django.forms.formsets.all_valid
>
> Since is_valid works the same for forms and formsets you can use this
> for plain forms too.
>
> Matthias
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



overriding clean method on ModelForm class

2009-07-30 Thread sico

Hey,

I had a problem recently that caused me some confusion!

I have a model that has a OneToOne field as the primary key.  When
adding a new record in the admin form and entering a key that already
existed, I wasn't getting the expected "record already exists" error,
instead it was just overwriting the existing record!!

The problem was because I was implementing my own "clean" method on
the AdminForm.  e.g.

class MyModelAdminForm(forms.ModelForm):
def clean(self):

return self.cleaned_data

as per the doco:
http://docs.djangoproject.com/en/1.0/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other

But this then ignores the standard form validation that should still
occur.  By adding a call to the super class clean method everything
became fine!

class MyModelAdminForm(forms.ModelForm):
def clean(self):
self.cleaned_data = super(MyModelAdminForm, self).clean()

return self.cleaned_data

Just be aware that any invalid data will be removed from cleaned_data

This is really a bug in the documentation I think... Can the doco be
updated??

Regards,
Simon
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



view/form with fields from multiple models

2009-07-23 Thread sico

Hi,

I want to be able to edit fields from several different models on the
same form/view.

The models are related one-to-one... can they be defined as "Inline"
forms in the admin system??  The documentation doesn't make any
mention of using inline forms for anything except parent child
relations so I'm thinking this may cause issues.

Whats the best way to handle this in a custom view?  Do I just simply
define forms for each model, pass them in separately to be displayed
in the template and then validate and save them individually on
saving?  The fields would need to be clearly distinguishable to which
model they belong using a prefix which is something that formsets use
to distinguish themselves

so... what is the best way to allow editing of fields from multiple
one-to-one models at once.

thanks!
Simon

p.s.
(I actually want to be able to edit multiple records of these in a
grid, but need to be able to edit one first!)
--~--~-~--~~~---~--~~
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: customizing admin template - how to refer to specific field

2009-07-22 Thread sico

This has been put in the "too hard" basket for now.  I'm upgrading
from django 0.96 to 1.0.2 and was hoping to make this custom view a
configured admin view but am leaving that till later now as it's
taking too much time away from porting the rest of the system.

On Jul 21, 11:43 am, sico  wrote:
> Yeah, that will do it, but it will get cumbersome quite quickly... I'm
> thinking if I override the change_view and add_view functions on the
> admin model I can set the fieldsets variable however I like!
>
> My system is down at the moment so I can't test it... does that sound
> like it will work?  I'll report back as soon as I can test it 
>
> On Jul 21, 11:32 am, Joshua Russo  wrote:
>
> > On Mon, Jul 20, 2009 at 10:26 PM,sico wrote:
>
> > > thats cool to know, but not quite what I'm after I don't think.  If
> > > there was a simple way to display the label, field and any errors all
> > > at once would be nice otherwise it gets quite cumbersome to be
> > > repeating that all each time.
>
> > > Basically what I want to be able to do is to show different fields
> > > depending on a data value
>
> > > e.g.
>
> > > if field1 = 1 then hide field7 else hide field8
>
> > I think you want to look at the different IF tags 
> > here:http://docs.djangoproject.com/en/dev/ref/templates/builtins/
--~--~-~--~~~---~--~~
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: customizing admin template - how to refer to specific field

2009-07-20 Thread sico

Yeah, that will do it, but it will get cumbersome quite quickly... I'm
thinking if I override the change_view and add_view functions on the
admin model I can set the fieldsets variable however I like!

My system is down at the moment so I can't test it... does that sound
like it will work?  I'll report back as soon as I can test it 

On Jul 21, 11:32 am, Joshua Russo  wrote:
> On Mon, Jul 20, 2009 at 10:26 PM, sico  wrote:
>
> > thats cool to know, but not quite what I'm after I don't think.  If
> > there was a simple way to display the label, field and any errors all
> > at once would be nice otherwise it gets quite cumbersome to be
> > repeating that all each time.
>
> > Basically what I want to be able to do is to show different fields
> > depending on a data value
>
> > e.g.
>
> > if field1 = 1 then hide field7 else hide field8
>
> I think you want to look at the different IF tags 
> here:http://docs.djangoproject.com/en/dev/ref/templates/builtins/
--~--~-~--~~~---~--~~
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: colMS and how to put stuff in sidebar??

2009-07-20 Thread sico

I'm thinking overriding the change_view on the admin model - add the
extra data to extra_context and then reference it as Rajeesh suggested
below...

On Jul 21, 9:08 am, sico  wrote:
> heh... right you are!
>
> But how do I make extra data from other models available?   Hmmm... is
> it in the Form object I do this?  Are formsets perhaps what I need?  I
> haven't yet figured out how they work  Does the admin site work
> okay with formsets ??
>
> thanks!
>
> On Jul 21, 12:02 am, rajeesh  wrote:
>
> > On Jul 20, 4:06 am, sico  wrote:
>
> > > Hi,
>
> > > Using django 1.0.2 and I'd like to put some extra read-only info in a
> > > sidebar on the editing forms for specific models.
>
> > > coltype= colMS looks perfect for this, but how/where do I tell django
> > > what I want to put in the sidebar??
>
> > > thanks,
> > > Simon
>
> > Try putting a sidebar block after the content block in your custom
> > model-specific change_form. Write whatever you want to put inside that
> > sidebar block.
--~--~-~--~~~---~--~~
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: customizing admin template - how to refer to specific field

2009-07-20 Thread sico

thats cool to know, but not quite what I'm after I don't think.  If
there was a simple way to display the label, field and any errors all
at once would be nice otherwise it gets quite cumbersome to be
repeating that all each time.

Basically what I want to be able to do is to show different fields
depending on a data value

e.g.

if field1 = 1 then hide field7 else hide field8

On Jul 20, 11:47 pm, rajeesh  wrote:
> On Jul 20, 9:38 am, sico  wrote:
>
>
>
> > Its quite simple to customize the admin template for a specific model
> > by creating a change_form.html in the templates/admin//
> > / directory.
>
> > But, is it possible to refer to particular fields in the model/form
> > directly?
>
> > Instead of using the loops:
> >    for fieldset in adminform:
> >        for line in fieldset:
> >            for field in line:
> >  
>
> > doing something like:
>
> > {{field.first_name.label}}  {{ field.first_name.field}}
> > {{field.last_name.label}}  {{ field.last_name.field}}
>
> Why not? If you've got a form with fields first_name & last_name, you
> may render it by hand as follows:
>
> {{ form.first_name.label_tag }}{{ form.first_name }}
> {{ form.last_name.label_tag }}{{ form.last_name }}
--~--~-~--~~~---~--~~
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: colMS and how to put stuff in sidebar??

2009-07-20 Thread sico

heh... right you are!

But how do I make extra data from other models available?   Hmmm... is
it in the Form object I do this?  Are formsets perhaps what I need?  I
haven't yet figured out how they work  Does the admin site work
okay with formsets ??

thanks!

On Jul 21, 12:02 am, rajeesh  wrote:
> On Jul 20, 4:06 am, sico  wrote:
>
> > Hi,
>
> > Using django 1.0.2 and I'd like to put some extra read-only info in a
> > sidebar on the editing forms for specific models.
>
> > coltype= colMS looks perfect for this, but how/where do I tell django
> > what I want to put in the sidebar??
>
> > thanks,
> > Simon
>
> Try putting a sidebar block after the content block in your custom
> model-specific change_form. Write whatever you want to put inside that
> sidebar block.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



customizing admin template - how to refer to specific field

2009-07-19 Thread sico

Its quite simple to customize the admin template for a specific model
by creating a change_form.html in the templates/admin//
/ directory.

But, is it possible to refer to particular fields in the model/form
directly?

E.g.

Instead of using the loops:
   for fieldset in adminform:
   for line in fieldset:
   for field in line:
 

doing something like:

{{field.first_name.label}}  {{ field.first_name.field}}
{{field.last_name.label}}  {{ field.last_name.field}}

etc...

??

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



colMS and how to put stuff in sidebar??

2009-07-19 Thread sico

Hi,

Using django 1.0.2 and I'd like to put some extra read-only info in a
sidebar on the editing forms for specific models.

coltype= colMS looks perfect for this, but how/where do I tell django
what I want to put in the sidebar??

thanks,
Simon
--~--~-~--~~~---~--~~
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: about a web site

2009-07-17 Thread Diego Eduardo Ahumada - SICO S.I. S.A.

2009/7/17 Michael :
> On Fri, Jul 17, 2009 at 1:30 PM, Lic. José M. Rodriguez Bacallao
>  wrote:
>>
>> anyone?
>>
>>
>> On 7/17/09, Lic. José M. Rodriguez Bacallao  wrote:
>> > hi folks, it's be a long time without writing to the list but now I'm
>> > back with a simple question, I need to know how much can cost to make
>> > a site like this:
>> >
>> > --
>> > Lic. José M. Rodriguez Bacallao
>> > Centro de Biofisica Medica
>> > -
>> > Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo
>> > mismo.
>> >
>

Hi! Why you ask? What's your plan? That someone build a site for you,
or build it for someone and want to know how much you can earn?

Diego

--~--~-~--~~~---~--~~
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: how to alter (add/del cols) the tables from the existing models

2009-07-17 Thread Diego Eduardo Ahumada - SICO S.I. S.A.

2009/7/17 Lokesh :
>
> Hi,
>
> Initially the table created with the following code
> Class user_privileges(models.Model):
>    user_id = models.ForeignKey(User)
>    is_deleted= models.CharField(null=False, blank=False,
> max_length=1)
>    is_email_active = models.CharField(null=False, blank=False,
> max_length=1)
>
> Now I would like to add the one more column to the "user_privileges"
> model
>    is_phone_active = models.CharField(null=False, blank=False,
> max_length=1)
>
> The changes are not taken place when I do the "manage.py syncdb" after
> adding the new column into the model.
>

Remember that "manage.py syncdb" only check if the table exits/not
exits, it doesn't check structures. So if all the model is in the
server, syncdb simply do nothing.

> Please guide me how do I modify the models after the initial creation.
>
> I am not supposed to drop the "user_privileges" table because this is
> linked to other tables as foreign key.
>
> Thanks in advance.
> --~--~-~--~~~---~--~~

I'm pretty new in Django, but i think that you need to make that
change manually in the database server, i mean: change the model
(adding the field) and change the structure of the table (adding the
field with the same characteristics).

Another option is to backup your data, drop all the tables, do
"manage.py syncdb" and recover the backup.

--~--~-~--~~~---~--~~
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: foreign key validation

2009-07-12 Thread sico

okay... seems the use of a Manipulator was the issue, and adding
raw_id_admin = True to the Foreign Key field definition fixed it!

On Jul 13, 9:58 am, sico  wrote:
>  reposting>
>
> Can anyone shed some light on how django validates foreign keys for
> me??
>
> I have a model that I'm writing a whole lot of records in a single
> request.  With the Foreign Key defined in the model it takes ages!!!
> Have about 100 records and it takes minutes.  When I change the field
> to CharField, it completes in a matter of seconds.
>
> The database constraint is still active, and executing a query against
> the database to check if the key exists completes in under 10
> milliseconds.
>
> I'm curious if anyone might know why the foreign key validation is
> taking so long to complete?!?!
>
> I'm thinking a cache tuning issue perhaps??
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



foreign key validation

2009-07-12 Thread sico



Can anyone shed some light on how django validates foreign keys for
me??

I have a model that I'm writing a whole lot of records in a single
request.  With the Foreign Key defined in the model it takes ages!!!
Have about 100 records and it takes minutes.  When I change the field
to CharField, it completes in a matter of seconds.

The database constraint is still active, and executing a query against
the database to check if the key exists completes in under 10
milliseconds.

I'm curious if anyone might know why the foreign key validation is
taking so long to complete?!?!

I'm thinking a cache tuning issue perhaps??
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



foreign key validation

2009-07-07 Thread sico

Can anyone shed some light on how django validates foreign keys for
me??

I have a model that I'm writing a whole lot of records in a single
request.  With the Foreign Key defined in the model it takes ages!!!
Have about 100 records and it takes minutes.  When I change the field
to CharField, it completes in a matter of seconds.

The database constraint is still active, and executing a query against
the database to check if the key exists completes in under 10
milliseconds.

I'm curious if anyone might know why the foreign key validation is
taking so long to complete?!?!

I'm thinking a cache tuning issue perhaps??
--~--~-~--~~~---~--~~
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: rollback transaction without an exception when transaction is tied to http requests

2009-06-29 Thread sico

So, using automatic transaction management, there is no way to cause a
transaction rollback without the user seeing the exception...

stink...

thanks for your help!

On Jun 30, 3:07 am, Karen Tracey  wrote:
> On Sun, Jun 28, 2009 at 11:14 PM, sico  wrote:
>
> > [snip]
>
> > However, I am still curious if there is a way to tell django to not
> > commit the transaction without the user seeing an exception
>
> Yes and no: I tried to describe that in my previous answer.  Yes, you can
> arrange to have the transaction be rolled back instead of being committed,
> and you can avoid having exceptions reflected to the user.  But no, there is
> no setting to tell Django to automatically rollback on error and not
> propagate the exception resulting from the error: your code must do that.
>
> First you have to use manual transaction management, so that you control
> when the updates get committed.  If you use the default autocommit behavior
> you cannot roll back already completed updates as they will be automatically
> committed as they are executed.
>
> Then you need to be aware, in your code, of what statements might raise
> exceptions.  You must write your code to explicitly handle the cases where
> exceptions may be raised and "do the right thing" instead of having them
> just propagate up and be reported as server errors.
>
> 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: rollback transaction without an exception when transaction is tied to http requests

2009-06-28 Thread sico

My apologies, poorly written question (was late on Friday and I should
have gone home!)

What I'm doing is writing several records to the database in a single
request.  The errors may occur due to validation problems and I'm
checking for these as I go.  However the problem occurs as follows:

validate record1
success - write record1

validate record2
success - write record2

validate record3
error - return validation error to user

However, the first two records have already been written and because
no exception occured the transaction would be committed.

The solution here of course is to do this:

validate record1
validate record2
validate record3

if all okay then
  write record1
  write record2
  write record3

I was a bit slow last week and this obvious solution didn't present
itself to me.

However, I am still curious if there is a way to tell django to not
commit the transaction without the user seeing an exception

thanks!


On Jun 26, 11:13 pm, Karen Tracey  wrote:
> On Fri, Jun 26, 2009 at 12:59 AM, sico  wrote:
>
> > Hi
>
> > Is it possible to rollback the transaction without raising an
> > exception when the transactions are tied to http requests??
> > I'm writing several records in one post call, if any fail I'd like to
> > rollback the transaction but return a nice error message to the user.
> > Surely I'm missing something as this seems quite a simple
> > requirement...
>
> You haven't given any indication of what you had tried here.  Since you are
> asking the question I gather whatever you have tried hasn't worked, but I'm
> not sure where you are running into trouble since I don't know what you've
> done.
>
> First, if you want to be able to roll back some already-completed operations
> due to a subsequent one failing, you will need to use something other than
> Django's default autocommit behavior, as described here:
>
> http://docs.djangoproject.com/en/dev/topics/db/transactions/#topics-d...
>
> The commit_manually decorator is probably what you want to use.
>
> Second, if you want to recover from attempting something that causes a
> database error, your code needs to catch whatever database exception is
> raised and recover.  Something like:
>
>     try:
>         instance = new_model.save()
>     except IntegrityError:
>         transaction.rollback()
>         ... whatever else you want to do to inform the user ...
>
> Your code must be prepared to handle the possible database errors, there is
> no setting to tell the framework to auomagically eat them and rollback the
> transaction (if it did, how would you know that had happened?).
>
> 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
-~--~~~~--~~--~--~---



rollback transaction without an exception when transaction is tied to http requests

2009-06-25 Thread sico

Hi

Is it possible to rollback the transaction without raising an
exception when the transactions are tied to http requests??
I'm writing several records in one post call, if any fail I'd like to
rollback the transaction but return a nice error message to the user.
Surely I'm missing something as this seems quite a simple
requirement...

thanks in advance
Simon
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



can't adapt error

2009-06-23 Thread sico

Hey,

I was getting a weird can't adapt error when saving a record.
Previous posts talked about charset conversions, unicode, etc...

The problem I had turned out to be trying to write an object reference
where I should have put the key value instead.

e.g.

rec["myfk"] = myObj

changed to:

rec["myfk"] = myObj.pk

and it fixed it.

Just posting incase anyone else encounters the same problem!

Regards,
Si

--~--~-~--~~~---~--~~
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 model and retrieve associated model/objects at same time

2009-01-19 Thread sico

btw... using 0.96 here...

On Jan 20, 9:27 am, sico  wrote:
> Hi,
>
> I'm filtering a model on some criteria... and based on the resultset I
> want to retrieve associated related models (all one-to-one
> relationships)
>
> Whats the most efficient way to do this without resorting to custom
> SQL?
>
> this is the best I can come up with:
>
> obj1s = MyModel1.filter(blah_blah=blah)
>
> data = []
> for obj1 in obj1s:
>     obj2 = MyModel2.get(pk=obj.pk)
>     obj3 = MyModel3.get(pk=obj.pk)
>     data.append({'obj1':obj1,
>                   'obj2':obj2,
>                   'obj3':obj3,
>                })
> return data
>
> I haven't checked but assuming this is going to execute 2 sql commands
> for each row returned by the first query not good!!
> Is there a way to tell django/python that I want to retrieve the
> related data from the other 2 models before looping through the
> queryset so it can figure out to do the necessary joins??
--~--~-~--~~~---~--~~
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 model and retrieve associated model/objects at same time

2009-01-19 Thread sico

Hi,

I'm filtering a model on some criteria... and based on the resultset I
want to retrieve associated related models (all one-to-one
relationships)

Whats the most efficient way to do this without resorting to custom
SQL?

this is the best I can come up with:

obj1s = MyModel1.filter(blah_blah=blah)

data = []
for obj1 in obj1s:
obj2 = MyModel2.get(pk=obj.pk)
obj3 = MyModel3.get(pk=obj.pk)
data.append({'obj1':obj1,
  'obj2':obj2,
  'obj3':obj3,
   })
return data

I haven't checked but assuming this is going to execute 2 sql commands
for each row returned by the first query not good!!
Is there a way to tell django/python that I want to retrieve the
related data from the other 2 models before looping through the
queryset so it can figure out to do the necessary joins??
--~--~-~--~~~---~--~~
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: form for model - with a few changes

2009-01-15 Thread sico

I suppose I want to know if there is anyway to customize the field
output at runtime to add properties like class, disabled etc...

Would rather not use javascript too .

On Jan 16, 1:53 pm, sico  wrote:
> doh!  its one thing being stupid... its another being stupid in front
> of a big crowd of people!
>
> if my field is readonly... it probably doesn't need a dropdown list
> does it??
>
> would still be nice to set date field text box class to vDateField to
> get nice pop-up thingy!
>
> On Jan 16, 1:38 pm, sico  wrote:
>
> > Hi,
>
> > I've inherited a django app - running on 0.96. So far, the people
> > before me have not created any views, and have just used the built-in
> > admin app to modify everything.
>
> > I want to create a view to control adding/editing records for a
> > specific model.
>
> > #So, I create form from the model like:
>
> > if add == True:
> >     myObj = ""
> >     myForm = form_for_model (MyModel)
> > else:
> >     myObj = MyModel.objects.get(pk=myId)
> >     myForm = form_for_instance(myObj)
>
> > form = myForm()   #  this got me at first!!
>
> > # Then I pass this form object to my template using render_to_response
>
> > return render_to_response('mytemplate.html',
> >        {'myId':myId,
> >         'myForm':form,
> >        },
> >        context_instance=RequestContext(request))
>
> > all good so far...
>
> > then, in my template... I thought about using
>
> > myForm.as_table
>
> > but... I want some fields to be disabled if you're editing the record
> > - still want them displayed, just not editable...
>
> > so I tried to display the fields all separately,
>
> > form.fieldname
>
> > that will let me display all the other fields, but to make my field
> > readonly I tried putting it in directly...  > to pass in the model object as well to get the data, but the big
> > kicker is the field is a lookup to a really big table
>
> > surely I'm trying to do this the hard way!!!
>
> > Is there a way to display a form field and specify it to be read-
> > only ???
>
> > Also, would be nice to be able to add class="vDateField" to my
> > datefields so it has the nice pop-up like the admin form
>
> > 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: form for model - with a few changes

2009-01-15 Thread sico

doh!  its one thing being stupid... its another being stupid in front
of a big crowd of people!

if my field is readonly... it probably doesn't need a dropdown list
does it??

would still be nice to set date field text box class to vDateField to
get nice pop-up thingy!

On Jan 16, 1:38 pm, sico  wrote:
> Hi,
>
> I've inherited a django app - running on 0.96. So far, the people
> before me have not created any views, and have just used the built-in
> admin app to modify everything.
>
> I want to create a view to control adding/editing records for a
> specific model.
>
> #So, I create form from the model like:
>
> if add == True:
>     myObj = ""
>     myForm = form_for_model (MyModel)
> else:
>     myObj = MyModel.objects.get(pk=myId)
>     myForm = form_for_instance(myObj)
>
> form = myForm()   #  this got me at first!!
>
> # Then I pass this form object to my template using render_to_response
>
> return render_to_response('mytemplate.html',
>        {'myId':myId,
>         'myForm':form,
>        },
>        context_instance=RequestContext(request))
>
> all good so far...
>
> then, in my template... I thought about using
>
> myForm.as_table
>
> but... I want some fields to be disabled if you're editing the record
> - still want them displayed, just not editable...
>
> so I tried to display the fields all separately,
>
> form.fieldname
>
> that will let me display all the other fields, but to make my field
> readonly I tried putting it in directly...  to pass in the model object as well to get the data, but the big
> kicker is the field is a lookup to a really big table
>
> surely I'm trying to do this the hard way!!!
>
> Is there a way to display a form field and specify it to be read-
> only ???
>
> Also, would be nice to be able to add class="vDateField" to my
> datefields so it has the nice pop-up like the admin form
>
> 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
-~--~~~~--~~--~--~---



form for model - with a few changes

2009-01-15 Thread sico

Hi,

I've inherited a django app - running on 0.96. So far, the people
before me have not created any views, and have just used the built-in
admin app to modify everything.

I want to create a view to control adding/editing records for a
specific model.

#So, I create form from the model like:

if add == True:
myObj = ""
myForm = form_for_model (MyModel)
else:
myObj = MyModel.objects.get(pk=myId)
myForm = form_for_instance(myObj)

form = myForm()   #  this got me at first!!

# Then I pass this form object to my template using render_to_response

return render_to_response('mytemplate.html',
   {'myId':myId,
'myForm':form,
   },
   context_instance=RequestContext(request))


all good so far...

then, in my template... I thought about using

myForm.as_table

but... I want some fields to be disabled if you're editing the record
- still want them displayed, just not editable...

so I tried to display the fields all separately,

form.fieldname

that will let me display all the other fields, but to make my field
readonly I tried putting it in directly... http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



temperamental ImportError

2008-11-12 Thread sico

just an FYI here as have fixed the problem.

was getting the error as described here
http://groups.google.com/group/django-users/browse_thread/thread/04fa8425d18f9242
but only every so often  then I noticed the ProcessID at the top
of the error was always the same.  Apache was running 11 processes, so
I killed that particular process and everything came right.

No idea why that process had a problem, but it was the lowest Process
ID number of the group so I'm assuming the first to startup, possibly
a timing issue??

We're running

OS: Fedora 9 Linux
Apache2
Python 2.5
Django 0.97-pre

And I believe its running as a Virtual Server if that may have any
impact

cheers,
Si

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---