Re: Django + Raspberry PI

2013-03-01 Thread Nicolas Emiliani
Shawn,

It was definitely pretty slow, but it works.
>
> Our stack includes nginx, gunicorn, Redis, MongoDB, PostgreSQL,
> supervisor, virtualenv, and probably other stuff I'm forgetting.
>
>
Well you are running a pretty interesting and (heavy?) stack, I've read
about DB engines being slow. Thanks for the data.


> It is a computer, after all. Just slow, not too much RAM, and with an
> ARM processor.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Django + Raspberry PI

2013-03-01 Thread Nicolas Emiliani
Hey guys!

Has anyone tried to run django + sqlite on a raspberry pi ? Any performance
issues ?

I'm about to start an app that provides a restful api and has to run on
RPI, it's going
to manage an automation service, so load is going to be pretty low.

Cheers.

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Best way to create an advanced search bar for the admin app.

2012-11-20 Thread Nicolas Emiliani
Hi people.

I have this huge class Foo that has a lot of attributes , not only that but
it has
an m2m relation with a through table that specifies values for each
relation,
and I want to be able to search using those values.
For example :

class Foo
 ...
class Attr
 ...

and the

class Has:
foo
attr
value

So basically Foo Has a given Attr with value X. The idea is having on top
of the search
bar at the list form a box that lets you choose (using check boxes) the
attributes and values
for each checked attribute (using text boxes).

My idea was redefining change_list.html to present that and somehow, I do
not know how yet,
override the search method at the admin site.

Does it sound good?
Has anyone done this?
Is there another approach?

Any comments will be highly appreciated.

Thanks!

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: Extend Django UserProfile

2012-11-01 Thread Nicolas Emiliani
On Thu, Nov 1, 2012 at 11:42 AM, Zoltán Bege <begezol...@gmail.com> wrote:

>
>
> On Thursday, November 1, 2012 11:29:38 AM UTC+2, Zoltán Bege wrote:
>>
>> I created an accounts app in my project, I 'd like to extend users to be
>> able to work with one or more partners. I need to define one or more admin
>> user for every partner.
>>
>> This is my accounts/models.py. In this case is_admin is set globally for
>> all partners, how do I have to set is_admin differently for every partner?
>>
>> class UserProfile(models.Model):
>> partners = models.ManyToManyField('**partners.Partner', null = True,
>> blank = True)
>> user = models.OneToOneField(User)
>> is_admin = models.BooleanField(default = False)
>>
>> def __unicode__(self):
>> return self.partners
>>
>> def create_user_profile(sender, instance, created, **kwargs):
>> if created:
>> UserProfile.objects.create(**user = instance)
>>
>> post_save.connect(create_user_**profile, sender = User)
>>
>> Thanks!
>>
>> --
>> Zoltán Bege
>>
>
Zoltàn, sorry but your last reply was only a copy of the first mail, maybe
something happened
with your email client ?



> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/J0DJKVoy-wcJ.
>
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: Extend Django UserProfile

2012-11-01 Thread Nicolas Emiliani
On Thu, Nov 1, 2012 at 6:29 AM, Zoltán Bege <begezol...@gmail.com> wrote:

> I created an accounts app in my project, I 'd like to extend users to be
> able to work with one or more partners. I need to define one or more admin
> user for every partner.
>
> This is my accounts/models.py. In this case is_admin is set globally for
> all partners, how do I have to set is_admin differently for every partner?
>
> class UserProfile(models.Model):
> partners = models.ManyToManyField('partners.Partner', null = True,
> blank = True)
> user = models.OneToOneField(User)
> is_admin = models.BooleanField(default = False)
>
> def __unicode__(self):
> return self.partners
>
> def create_user_profile(sender, instance, created, **kwargs):
> if created:
> UserProfile.objects.create(user = instance)
>
> post_save.connect(create_user_profile, sender = User)
>
>
Hi, if you are using the Admin site contrib application you can do this :

https://docs.djangoproject.com/en/dev/topics/auth/#adding-userprofile-fields-to-the-admin

That way whenever you create a user, you'll have the inlined form that
belongs to
your user profile and you can simply check the is_admin checkbox.


Thanks!
>
> --
> Zoltán Bege
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/x4UAl7Mc-w8J.
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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-ajax giving 403

2012-10-30 Thread Nicolas Emiliani
On Tue, Oct 30, 2012 at 1:03 PM, Chris Pagnutti <chris.pagnu...@gmail.com>wrote:

> Hi.  I'm trying to make some AJAX calls using django-ajax
> https://github.com/joestump/django-ajax
>
> But when I make the call, Chrome's console gives POST
> http://127.0.0.1:8000/ajax/my_app/my_ajax_view.json<http://127.0.0.1:8000/ajax/members/save_homepage_element.json>403
>  (FORBIDDEN)
> If I visit the url directly in my browser, I get {"data":{"message":"Invalid
> HTTP method used.","code":400},"success":false}
>
> Reading the docs, it seems likely that the problem may be with related to
> not explicitly passing the csrf token in my jquery .ajax() call. But the
> django-ajax docs/instructions don't mention anything about this, and I
> kinda figured the whole point of django-ajax is to simplify these matters.
>
> Anyone use django-ajax that can help? What do most django developers use
> for ajax? I've checked out Dajax, but I find it a bit much, yet I'm willing
> to give it, or some other package another try.
>

I used dajaxice  successfully (it is fearly simple) in a project that
updates a google map with markers every time you move the map. It worked
just fine. As Tom said my views also returned JSON. Regarding de CSRF token
you only need to include the CSRF tag at the view tamplate and that's
mainly it.

Check this example out :

http://www.dajaxproject.com/dajaxice/



> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/eTD4Xw3RQxUJ.
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: a way to display a model formset in a ModelAdmin ?

2012-10-25 Thread Nicolas Emiliani
>
>
> Create New adminmodel class and define fieldsets... For example
> http://www.f2finterview.com/web/Django/22/ it is clearly explain you
>
>
Hi Stephen, thanks for the reply, but it doesn't solve it since every field
specified
in the fieldset at the Model admin needs to either exist in Model or in the
ModelForm,
and since the number of Images that I want to display is variable (let's
say between 1 and N)
I can't have N Image fields at the form, what I need is somewhat of a field
that spawns
into multiple fields based on the amount of images that I want to display.
I'm starting
to think that maybe using a many-to-many field with a custom widget might
do the job.


> On Thu, Oct 25, 2012 at 3:51 AM, Nicolas Emiliani <or3s...@gmail.com>wrote:
>
>> Hi,
>>
>> As the subject states, is there a way to display a model formset in a
>> ModelForm?
>>
>> The thing is that I have a Verification model with its ModelAdmin, and
>> then I have
>> an ImageModel that has no ForeignKey to the Verification model (and I
>> intend to keep
>> it that way) so I can not inline it into the VerificationAdmin and I
>> would like to show
>> a list of Images in my VerificationAdmin based on a queryset performed (i
>> assume) at
>> __init__ method of VerificationAdminForm. How could this be accomplished?
>>
>> This is how it goes:
>>
>> class Image(models.Model):
>>
>>
>> class Verification(models.Model):
>>
>>
>> class VerificationAdminForm(forms.ModelForm):
>>
>>
>> class VerificationAdmin(admin.ModelAdmin):
>>form = VerificationAdminForm
>>model = Verification
>>fieldsets = [ ... ]
>>
>> Any ideas would be greatly appreciated.
>>
>> Thanks in advance.
>>
>> --
>> Nicolas Emiliani
>>
>> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>>
>> --
>> 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.
>>
>
>
>
> --
> Thanks & Regards
> Stephen S
>
>
>
> Website: www.f2finterview.com
> Blog:  blog.f2finterview.com
> Tutorial:  tutorial.f2finterview.com
> Group:www.charvigroups.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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: Only one profile type of multiple user profiles types gets created.

2012-10-24 Thread Nicolas Emiliani
> The thing is that now the only profile that ever gets created when
> creating a  user
> is AgentProfile. I can't get it to create an AuditorProfile not even by
> setting the agency
> field on the form.
>
>
>
Ok, just for the record, I did it the shameless way.
Only one profile class with an profile type attribute.
Nasty but it works.


>
> Thanks!
>
> --
> Nicolas Emiliani
>
> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



a way to display a model formset in a ModelAdmin ?

2012-10-24 Thread Nicolas Emiliani
Hi,

As the subject states, is there a way to display a model formset in a
ModelForm?

The thing is that I have a Verification model with its ModelAdmin, and then
I have
an ImageModel that has no ForeignKey to the Verification model (and I
intend to keep
it that way) so I can not inline it into the VerificationAdmin and I would
like to show
a list of Images in my VerificationAdmin based on a queryset performed (i
assume) at
__init__ method of VerificationAdminForm. How could this be accomplished?

This is how it goes:

class Image(models.Model):
   

class Verification(models.Model):
   

class VerificationAdminForm(forms.ModelForm):
   

class VerificationAdmin(admin.ModelAdmin):
   form = VerificationAdminForm
   model = Verification
   fieldsets = [ ... ]

Any ideas would be greatly appreciated.

Thanks in advance.

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



Only one profile type of multiple user profiles types gets created.

2012-10-22 Thread Nicolas Emiliani
Hi!

I'm trying to use different types of profiles on django 1.4, I basically
followed this :

https://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users

The thing is that the docs only apply if you have one profile type, and i
have four. Doing
some research i found that setting a base profile and inheriting from it
you can can get multiple
profile types. So this is what I did :

class HomesUserProfile(models.Model):
user = models.OneToOneField(User)

class AgentProfile(HomesUserProfile):
homes_user = models.OneToOneField(HomesUserProfile)
agency = models.ForeignKey(Agency, verbose_name='Agencia')
branch = models.ForeignKey(Branch, verbose_name='Sucursal')

class AuditorProfile(HomesUserProfile):
homes_user = models.OneToOneField(HomesUserProfile)
agency = models.ForeignKey(Agency, verbose_name='Agencia')

and then :

AUTH_PROFILE_MODULE = 'homes.HomesUserProfile'

class UserAdmin(contrib_auth.UserAdmin):
inlines=(AgentProfileInline, AuditorProfileInline)

The thing is that now the only profile that ever gets created when creating
a  user
is AgentProfile. I can't get it to create an AuditorProfile not even by
setting the agency
field on the form.

Any ideas what is going on? I'm clueless

Thanks!

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: Adding a new row to the database in user form

2012-10-15 Thread Nicolas Emiliani
On Mon, Oct 15, 2012 at 3:16 AM, Satinderpal Singh <
satinder.goray...@gmail.com> wrote:

> Hello,
> I want to add a new row in the existing database table by using add
> button in the html form from the user as user can create as much rows
> in the table as he needed, how will i add this?
> Thanks, in advance.
>
>
Hi, correct me if I'm wrong but, it seems that you are talking about
formsets. Check this out :

https://docs.djangoproject.com/en/dev/topics/forms/formsets/


> --
> Satinderpal Singh
> http://satindergoraya.blogspot.in/
> http://satindergoraya91.blogspot.in/
>
> --
> 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.
>
>


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



django-guardian + field permissions ?

2012-10-07 Thread Nicolas Emiliani
Hi,

I'm using django-guardian to implement in the admin panel
per object permissions. So far so good. Now I've stumbled
upon the following issue. If I create an instance of a Foo
model (a_foo from now on) and then assign to the user that created the
instance (a_user from now on) change_foo and delete_foo permisions,
then, the a_user will also be able to change it's own permissions
on a_foo through the 'object permissions' button (the one next
to the 'history' button).

Even though this is absolutely logical, I do not want that a_user
that belongs to a specific group being able to change his own
objects permissions. It would be somewhat of field permission
over object permissions.

Any way to accomplish this ?

Thanks in advance.

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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-guardian 404 on save.

2012-10-06 Thread Nicolas Emiliani
On Sat, Oct 6, 2012 at 4:41 PM, Nicolas Emiliani <or3s...@gmail.com> wrote:

> Hi,
>
> I'm implementing django-guardian within the admin site and I'm having the
> following issue.
> If I create a model instance through the admin panel and then try to
> modify it
> (even using the super admin) I get a 404 error.
>

Replying to myself. The problem was not with django-guardian the problem
was the method
change_view at the model.Admin, still do not know why, I'll repost.

Sorry for the inconvenience

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



display thousand separator.

2012-09-30 Thread Nicolas Emiliani
Hi list!

I'm having a localization issue. The thing is that I have an AdminForms
that contains
a value field (wich is a model.BigInteger at the model ) and when the value
is displayed
at the admin form I would like it to show the THOUSAND_SEPARATOR as
configured
in setting.py. So this is what I've done

USE_I18N = True
USE_L10N = True
USE_THOUSAND_SEPARATOR = True
THOUSAND_SEPARATOR = '.'
DECIMAL_SEPARATOR = ','

and then at the init method of my admin form I did this :

self.fields['value'].localize = True
self.fields['value'].is_localized = True

So now I can input for example:
5.000.000
but after saving it it shows
500

Any solutions besides doing some javascript tampering?

Thanks!


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: Automatically create an InlineForm object inside an admin page

2012-08-30 Thread Nicolas Emiliani
On Tue, Aug 28, 2012 at 7:20 PM, Jill Green <jill.green...@gmail.com> wrote:

> I hope someone has come across this problem before because it's driving me
> nuts.  Basically I have a model, Partner and it has a PartnerAdmin page.
>  Inside the partner I have another model called Data that is an Inline to
> the Partner.  I used the model.ForeignKey in the Data to reference it back
> to the Partner instance.  What I want to do is everytime I create a new
> Partner and click to save it to automatically create one Data object (sort
> of a requirement) for all new partners.  It currently looks like this:
>
> PartnerAdmin:
>  #stuff
>  inlines = ['DataInline',]
>
> Data:
>  name= model.Char
>  #more stuff
>
> DataInline(admin.TabularInline):
>extra = 0
>form = DataForm
>formset = DataFormSet
>
> I have tried using the initial data and trying to bind a form from it but
> it won't work.  Please any help would be appreciated.
>
>
Maybe implementing the save_model method at PartnerAdmin can do the trick.
Here is the doc :

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model

You should use the change parameter to check if it's a new object or not.

 --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/YvGlPmf_HtEJ.
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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 IMAGESTORE app help to - create a photo album

2012-08-29 Thread Nicolas Emiliani
On Wed, Aug 29, 2012 at 4:57 AM, hasan faisal <faisal...@gmail.com> wrote:

> My project require- user photo upload and album creation ( like facebook
> photo album ) ,where one user can upload multiple photos in one album , can
> upload multiple album.
>
> After search I found django imagestore app is handy enough. But
> unfortunately I did not find any example or tutorial about imagestore.I am
> very new in django. Need some example tutorial about this app..I also
> checked imagekit and photologue, but among all these it seems imagestore is
> better. whats your opinion?
>
> I am very new in django. Any example link of how to use imagestore to
> create photo album would be very helpful..
>
That link says that the package contains a pre-configured project as an
example. Have you checked that out ?

http://imagestore.readthedocs.org/en/latest/example.html


> Can you suggest better way to create a photo album?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/_duq35Tlu3UJ.
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: Column widths in TabularInline

2012-08-28 Thread Nicolas Emiliani
On Tue, Aug 28, 2012 at 3:47 AM, Vikas Rawal <
vikasli...@agrarianresearch.org> wrote:

> >
> > The problem is that the #id is different for each row of the tabular
> > inline object.
> >
> > it takes the form
> >
> > id="id_member_set-0-name" for the first row,
> id="id_member_set-1-name"
> > for the second row, etc.
> >
> > Therefore #whatever does not work. Is there a way of using regex or
> > something like that to cover all the above formulations of "id".
> >
> >
> >
> > Yes there is, but this is no django thing you are asking, using jquery
> you can
> > accomplish that :
> >
> > http://api.jquery.com/attribute-starts-with-selector/
> >
> >  jQuery('[id^=id_member_set]').each(so_stuff)
> >
> > Check the web, there is a __LOT__ of info on this.
>
>
> The problem I am posting it to django list is because the problem is
> obviously related to the way django works. Various solutions to the
> problem, none of which have worked so far, have either been using
> python/django or css (and now, jquery).
>
>
you can not expect to use a web framework and tackle this type of
issue without knowing some web basics. js/css/html are things you need to
know.


> I am new to all of these and would prefer if the problem could be
> solved without going to jquery. It is a simple django model and I have
> picked up some sense of css. But java/jquery is totally alien to me.
>
>
One more thing you can try is passing the attrs={'width':'100px'} params to
each widget of the column fields in the form and see what happens.

https://docs.djangoproject.com/en/dev/ref/forms/widgets/

Otherwise, I don't think you have another choice but getting into css,
creating the css classes and setting them in the widgets or maybe altering
the style with some js framework.

Regards.

Vikas
>
> --
> 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.
>
>


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: expand fieldset by choice

2012-08-27 Thread Nicolas Emiliani
On Mon, Aug 27, 2012 at 10:51 AM, Axel Rau <axel@chaos1.de> wrote:

>
> Am 27.08.2012 um 15:04 schrieb Nicolas Emiliani:
>
> >
> > Through JS, you need to implement a script that binds to the change event
> > and then changes the collapse css call for the specific div. You may want
> > to look
> > at jQuery, although this is out of scope of the list.
> >
> > Once you have your script ready you need to tell your admin form to use
> it,
> > read this
> > it explains how you do that.
> >
> > https://docs.djangoproject.com/en/dev/topics/forms/media/
>
> Thanks for the explanation, but JS is not an option here.
> Any other solution available?
>
>
Not that I know of, scripting on the client side is implemented with JS.


> Axel
> ---
> PGP-Key:29E99DD6  ☀ +49 151 2300 9283  ☀ computing @ chaos claudius
>
> --
> 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.
>
>


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: expand fieldset by choice

2012-08-27 Thread Nicolas Emiliani
On Mon, Aug 27, 2012 at 6:36 AM, Axel Rau <axel@chaos1.de> wrote:

> To clarify:
> --- from admin.py:
> class MailboxAdmin(admin.ModelAdmin):
> list_display = ('localpart', 'localdomainfk', 'type',
> 'aliastargetaddresses', 'created', 'updated')
> fieldsets = (
> (None, {
> 'fields': (('localpart', 'localdomainfk'),
> 'accountfk', 'lifetime', 'type')
> }),
> (_('Mailbox'), {
> 'classes': ('collapse',),
> 'fields': ('aoxuserid', 'quota')
> }),
> (_('Alias'), {
> 'classes': ('collapse',),
> 'fields': ('aliastargetaddresses',)
> }),
> (None, {
> 'fields': ('remarks',)
> })
> )
>
> ...
> admin.site.register(Mailbox, MailboxAdmin)
>
> --- from models.py:
> class Mailbox(models.Model):
> id = models.AutoField(primary_key=True)
> localpart = models.CharField(_('Localpart'), max_length=40)
> localdomainfk = models.ForeignKey(Localdomain,
>  verbose_name=_('Domainteil'), db_column='localdomainfk')
> accountfk = models.ForeignKey(Account, db_column='accountfk')
> aoxuserid = models.IntegerField(_('IMAP Server User ID'), null=True,
> blank=True)
> serverpassword = NULLCharFieldM(_('Server Password'), null=True,
> blank=True, max_length=40)
> quota = models.PositiveSmallIntegerField(_('IMAP Server
> Quota'),null=True, blank=True)
> type = models.CharField('Typ', max_length=1, choices=
> (('A', _('Alias')), ('M', _('Mailbox')), ('S', _('Systemalias'
> aliastargetaddresses = NULLCharFieldM(_('Alias
> Targetaddress'),null=True, blank=True, max_length=60)
> status = models.CharField(_('Status'), max_length=1, choices=
> (('N', _('New')), ('E', _('Enabled')), ('L', _('Locked')), ('D',
> _('Disabled')), ('C', _('Closed'))),
> default='N')
> created = models.DateField(_('Created'), auto_now_add=True)
> updated = models.DateField(_('Updated'), auto_now=True)
> remarks = models.TextField(_('Remarks'),null=True, blank=True)
> lifetime = TimedeltaDayFieldM(_('Lifetime of Data'), max_length=10)
> class Meta:
> db_table = u'mailbox'
> verbose_name = _('Mailbox')
> verbose_name_plural = _('Mailboxes')
> ordering = ['localpart']
> unique_together = ('localpart', 'localdomainfk')
> def __unicode__(self):
> return self.localpart+'@'+self.localdomainfk.name
> ---
> If the user selects 'Alias' or 'Systemalias' in the type choice, I would
> like to see the 'Alias' fieldset expanded.
> If he selects 'Mailbox', the fieldset 'Mailbox'.
>
> How can I do this in admin site?


Through JS, you need to implement a script that binds to the change event
and then changes the collapse css call for the specific div. You may want
to look
at jQuery, although this is out of scope of the list.

Once you have your script ready you need to tell your admin form to use it,
read this
it explains how you do that.

https://docs.djangoproject.com/en/dev/topics/forms/media/



> Axel
>
> Am 27.08.2012 um 01:11 schrieb Nicolas Emiliani:
>
> > On Sun, Aug 26, 2012 at 5:03 PM, Axel Rau <axel@chaos1.de> wrote:
> >
> >> In my admin site, I have a fieldset which depends on a choice.
> >> I would like to control expansion of the related fieldset by the choice
> >> instead of the standard widgets.
> >> How can I do this?
> >>
> >
> > I don't understand clearly what you want, but, correct me if I'm wrong,
> you
> > have some field and by doing something on it, maybe selecting it ? you
> want
> > to something else on some other fields, maybe show/hide them ?
> >
> > If this is what you are looking for, you could use javascript to do the
> > magic, you can tell the admin form to use a specific js script and u can
> > even generate that js dynamically.
> >
> > If this is not helpful please be more specific.
> >
> >
> >
> >> Axel
> >> ---
> >> PGP-Key:29E99DD6  ☀ +49 151 2300 9283  ☀ computing @ chaos claudius
> >>
> >> --
> >> 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://grou

Re: Column widths in TabularInline

2012-08-27 Thread Nicolas Emiliani
On Mon, Aug 27, 2012 at 3:34 AM, Vikas Rawal <
vikasli...@agrarianresearch.org> wrote:

> > >There is a field in my model called "name". What do I give in the css
> > >file to reduce its width to say 100px?
> >
> > This is css rather than Django but this is what I did to make my
> > input field wider ...
> >
> > .wider .vTextField {
> > width: 60em !important;
> > }
> >
> > If you view source in your browser you should see input elements
> > with class="vTextField" among others depending on the type of
> > element.
> >
> > However, you should also see that each field has its own
> > id="whatever" so you can address each field individually in your css
> > file using #whatever .vTextField {...}.
>
> The problem is that the #id is different for each row of the tabular
> inline object.
>
> it takes the form
>
> id="id_member_set-0-name" for the first row, id="id_member_set-1-name"
> for the second row, etc.
>
> Therefore #whatever does not work. Is there a way of using regex or
> something like that to cover all the above formulations of "id".
>
>
Yes there is, but this is no django thing you are asking, using jquery you
can accomplish that :

http://api.jquery.com/attribute-starts-with-selector/

 jQuery('[id^=id_member_set]').each(so_stuff)

Check the web, there is a __LOT__ of info on this.

Vikas
>
> --
> 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.
>
>


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: widget construction issue

2012-08-27 Thread Nicolas Emiliani
On Mon, Aug 27, 2012 at 3:54 AM, Melvyn Sopacua <m.r.sopa...@gmail.com>wrote:

> On 27-8-2012 1:21, Nicolas Emiliani wrote:
>
> > The thing is that the GridWidget.__init__ method does not get executed
> > each time I access the form that contains it, so if the queryset changes
> the
> > widget gets 'obsolete'.
>
> That's because the widget is merely the piece that get rendered. It's
> driven by the form field and the form field should be the one managing
> the available choices.
>
>
I see ... since the field also has the queryset I can make it reload the
multi widget
_widgets and that should fix it, that way responsibilities seem to be
pretty clear to.

Thanks!


> --
> Melvyn Sopacua
>
> --
> 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.
>
>


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



widget construction issue

2012-08-26 Thread Nicolas Emiliani
Hi,

I built a widget class that inherits form MultiWidget and it looks like
this :

class GridWidget(forms.MultiWidget):

def __init__(self, attrs=None, queryset=None):
self.queryset = queryset
_widgets = []
for record in self.queryset:
.
do stuff
.
super(GridWidget, self).__init__(_widgets, attrs)

This basically adds widgets to the _widgets var based on the queryset.

Then I have some form that has a field like :

class PersonAdminForm(forms.ModelForm):

  attrs = MultiTypeField( \
label='Attributes',
queryset=Attribute.objects.all()
widget=GridWidget(queryset=Attribute.objects.all()),
)

The thing is that the GridWidget.__init__ method does not get executed
each time I access the form that contains it, so if the queryset changes the
widget gets 'obsolete'.

Is this some cache issue ? is there any way to force the widget
construction each time i
access the form containing it ?

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: expand fieldset by choice

2012-08-26 Thread Nicolas Emiliani
On Sun, Aug 26, 2012 at 5:03 PM, Axel Rau <axel@chaos1.de> wrote:

> In my admin site, I have a fieldset which depends on a choice.
> I would like to control expansion of the related fieldset by the choice
> instead of the standard widgets.
> How can I do this?
>

I don't understand clearly what you want, but, correct me if I'm wrong, you
have some field and by doing something on it, maybe selecting it ? you want
to something else on some other fields, maybe show/hide them ?

If this is what you are looking for, you could use javascript to do the
magic, you can tell the admin form to use a specific js script and u can
even generate that js dynamically.

If this is not helpful please be more specific.



> Axel
> ---
> PGP-Key:29E99DD6  ☀ +49 151 2300 9283  ☀ computing @ chaos claudius
>
> --
> 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.
>
>


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: ModelMultipleChoiceField with MultiWidget ?

2012-08-26 Thread Nicolas Emiliani
Finally, I'm starting to see some light and it is almost working.

>From what I see I reckon you will need to create both a custom field and a
> custom widget!
>
> I think so because if you have TextInputs validation may fail on the
> ModelMultipleChoiceField?
>

Yes, they do,  because it checks that the value is a pk
on the related table (attribute in this case)

I would think you need to override the methods: __init__, clean, to_python
> and compress.
>
>

With __init__ and clean is enough


> I think you will also need to create a more customized widget inheriting
> directly from MultiWidget?
> I think you would need to override the methods: __init__, render,
> decompress
>

Yes also,


>
> But I'm no expert ;-(
>
>
Well, you are closer than I am :)

Thanks for the help.


>
> On Sun, Aug 26, 2012 at 7:42 PM, Nicolas Emiliani <or3s...@gmail.com>wrote:
>
>> Hi,
>>
>> I've been struggling with this for the past two weeks, and i think it's
>> time to ask.
>>
>> I have and admin form that has a ModelMultipleChoiceField that is used to
>> display
>> a ManyToMany model field that specifies a through model
>>
>> class Person(models.Model):
>> name = models.CharField(max_length=10)
>> attributes = models.ManyToManyField('Attribute',through='Has',
>> blank=True, null=True)
>>
>> class Has(models.Model):
>> person = models.ForeignKey('Person')
>> attribute = models.ForeignKey('Attribute')
>> value = models.CharField(max_length=10)
>>
>>
>> class Attribute(models.Model):
>> name = models.CharField(max_length=10)
>> atype = models.CharField(max_length=2,
>>   choices=(('TF','true/false'),
>>('IN','text')))
>>
>>
>> class PersonAdminForm(forms.ModelForm):
>>
>> class Meta:
>> model = Person
>>
>> attrs = forms.ModelMultipleChoiceField( \
>> label='Attributes',
>> queryset=Attribute.objects.all(),
>> widget=forms.CheckboxSelectMultiple(),
>> )
>>
>>
>> This CheckboxSelectMultiple works fine, but I want to be able to render
>> each relation according to the Attribute.atype value, meaning if it is TF,
>> then tender it as a CheckBox, if it is IN the render it as an InputText
>>
>> I inherited from CheckboxSelectMultiple so it does that, but then when I'm
>> on the admin form and for one specific attribute of type IN, rendered as a
>> TextInput,  I set a value (let's say 500) and then press save , the method
>>
>> SelectMultiple.value_from_datadict gets called and passed as data :
>>
>> > [u'GWLnuoTSTjjLmpYOizodBA4VA1FmwdQw'],
>> u'_continue': [u'Save and continue editing'], u'name': [u'nico'],
>> u'attrs': [ u'2']}>
>>
>> And this is what has been driving me nuts!
>>
>> u'attrs': [ u'2'],
>>
>> As you can see it only passes the id of the attribute, not the id and the
>> value. What I
>> need is something like
>>
>> u'attrs': [ (u'2','500')],
>>
>> Any ideas on how to fix this ?
>>
>> Thanks!
>>
>> --
>> Nicolas Emiliani
>>
>> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>>
>> --
>> 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.
>>
>
>  --
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



ModelMultipleChoiceField with MultiWidget ?

2012-08-26 Thread Nicolas Emiliani
Hi,

I've been struggling with this for the past two weeks, and i think it's
time to ask.

I have and admin form that has a ModelMultipleChoiceField that is used to
display
a ManyToMany model field that specifies a through model

class Person(models.Model):
name = models.CharField(max_length=10)
attributes = models.ManyToManyField('Attribute',through='Has',
blank=True, null=True)

class Has(models.Model):
person = models.ForeignKey('Person')
attribute = models.ForeignKey('Attribute')
value = models.CharField(max_length=10)


class Attribute(models.Model):
name = models.CharField(max_length=10)
atype = models.CharField(max_length=2,
  choices=(('TF','true/false'),
   ('IN','text')))


class PersonAdminForm(forms.ModelForm):

class Meta:
model = Person

attrs = forms.ModelMultipleChoiceField( \
label='Attributes',
queryset=Attribute.objects.all(),
widget=forms.CheckboxSelectMultiple(),
)


This CheckboxSelectMultiple works fine, but I want to be able to render
each relation according to the Attribute.atype value, meaning if it is TF,
then tender it as a CheckBox, if it is IN the render it as an InputText

I inherited from CheckboxSelectMultiple so it does that, but then when I'm
on the admin form and for one specific attribute of type IN, rendered as a
TextInput,  I set a value (let's say 500) and then press save , the method

SelectMultiple.value_from_datadict gets called and passed as data :



And this is what has been driving me nuts!

u'attrs': [ u'2'],

As you can see it only passes the id of the attribute, not the id and the
value. What I
need is something like

u'attrs': [ (u'2','500')],

Any ideas on how to fix this ?

Thanks!

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: ManyToManyField errors.

2012-08-21 Thread Nicolas Emiliani
On Mon, Aug 20, 2012 at 4:31 PM, MN TS <mnt...@gmail.com> wrote:

> Hello
> I'm new in Django using 1.4version.
> So got some error.
>
> 'myapp.models.AdversiteImages'> has no ForeignKey to  'myapp.models.Adversite'>
>
> *
> MODEL*
>
> class AdversiteImages(models.Model):
> image = models.FileField(u'Photo' ,
> upload_to='adversiteimage/%Y/%m/%d', null=True, blank=True)
>
> class Adversite(models.Model):
> category = models.ForeignKey(AdversiteCategory, verbose_name=u'Зарын
> ангилал', related_name='adv_cat', blank=True, null=True)
> image_many = models.ManyToManyField(AdversiteImages,
> verbose_name=u'Photos',related_name="photos")
> title = models.CharField(u'Title', max_length=128)
> body = models.TextField(u'Description')
>
>
> *ADMIN*
>
> class
> AdversiteImagesInline(admin.TabularInline):
>
> model = Adversite.image_many.through
> extra = 1
>
> class AdversiteAdmin(admin.StackedInline):
> fieldsets = ((u'Ерөнхий',
> {'fields':('category','title','body','code')}),
>  (u'Тайлбар',
> {'fields':('price','phone','email','image1','image2','image3','image4','image5'
>
> ,'is_active','is_special','is_premium','start_at','finish_at')}))
> list_display = ('category','title','code','is_active','is_special')
> search_fields = ('category','title','code','is_active')
> model = Adversite.image_many.through
>
> Please help me.
>
>

Well, this is just a guess, but you are setting the model in the form as
the through attribute of an M2M relationship
and that might the problem, have you tried explicitly declaring the through
parameter in the M2M like it says here?

https://docs.djangoproject.com/en/dev/topics/db/models/#intermediary-manytomany




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



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: ManyToMany through parameter bug workaround.

2012-08-18 Thread Nicolas Emiliani
>
> Here I can store the value for the relationship when saving the Model in
> the DB.
>
> If anyone has a better solution, suggestion, comment or thinks this is
> going
> to make me rot in hell please let me know.
>

Well, I kept on reading and I found a clean solution :

It's explained here, the same happened to this guy and a workaround is
provided.
The code in  MHCs response example has a few errors, but the idea is pretty
clear.

http://stackoverflow.com/questions/2854350/django-admin-many-to-many-listbox-doesnt-show-up-with-a-through-parameter

Hope it saves some headaches.



> --
> Nicolas Emiliani
>
> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



ManyToMany through parameter bug workaround.

2012-08-18 Thread Nicolas Emiliani
Hi,

I was trying to create an m2m relationship using the 'through' parameter
 because
I want to have an additional field in the relation table. The idea was to
render this
using CheckboxSelectMultiple.

The thing is that when I add the model m2m field to the 'fieldset' field at
the
ModelForm it throws an exception :

'HomeAdmin.fieldsets[4][1]['fields']' can't include the ManyToManyField
field 'attributes' because 'attributes' manually specifies a 'through'
model.

Apparently this is a BUG pointed out here :

https://groups.google.com/forum/?fromgroups#!topic/django-users/nWpb0RjoTJ0%5B1-25%5D

Basically if you use the 'through' parameter to use a relation table that
contains an extra field/s
you can't render it using a CheckboxSelectMultple widget, not even if the
extra field allows null
values.

I thought of fixing it this way (a nasty hack) :

class A(models.Model):
  .
  .
  foos = models.ManyToManyField('Foo')

class Foo(models.Model):
  name = CharField

And here comes the nasssty

class FooRelationshipValue(models.Model):
  a   =  ForeingKey(A)
  foo = ForeingKey(Foo)
  value = DateField

Here I can store the value for the relationship when saving the Model in
the DB.

If anyone has a better solution, suggestion, comment or thinks this is
going
to make me rot in hell please let me know.

Thanks.

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: Dynamic form field type.

2012-08-06 Thread Nicolas Emiliani
On Sun, Aug 5, 2012 at 9:08 PM, Melvyn Sopacua <m.r.sopa...@gmail.com>wrote:

> Hi,
>
> On 6-8-2012 0:09, Nicolas Emiliani wrote:
>
> > I have three Models,
> >
> > Home, HomeAttributeType and HomeAttributeValue. HomeAttributeValue has
> > an FK to HomeAttributeType and one to Home.
> >
> > The idea is that the user can add as many HomeAttributeTypes as he wants
> and
> > set the data type of the former. ie :
> >
> > ha1 = HomeAttributeType
> > ha1.name = 'FooAttr2'
> > ha1.type = 'boolean'
> >
> > ha2 = HomeAttributeType
> > ha2.name = 'FooAttr2'
> > ha2.type = 'numeric'
> >
> > So, now the user when creating a Home through a ModelAdmin, has the Admin
> > for the HomeAttributeValue inlined, and so he can set, for example, for
> > that home
> > a FooAttr1 selecting in from the Drop Down menu.
>
> Ok, so for example:
> ha1.name = 'Garden'
> ha1.type = 'boolean'
>
> ha2.name = 'Rooms'
> ha2.type = 'numeric'
>
> Does this sound correct?
>
>
Yes, that is correct



> > And here comes the black magic, If he selects FooAttr1 the value field
> for
> > the HomeAttributeValue
> > should render itself as radio button (yes/no) and if it where FooAttr2 it
> > should render itself as
> > an InputText. I can easily do this with JS, but what I can't do is to
> > somehow add a bunch
> > of hidden inputs that can relate each HomeAttributeType to what they
> should
> > render to.
>
> And you don't need to. You would solve this with dynamically generated
> JavaScript. Create a mapping from HomeAttributeType to the right widget
> and connect an onchange event on the select widget.
> Something like:
> 
> ...
> 
> The javascript function render_widget gets the homeattributetype id
> passed to it.
> And the template for the javascript would be like:
> function render_widget(id)
> {
> {% for attr in attribute_types %}
> if( id == {{ attr.id }} ) {
> render_{{ attr.type }}()
> }
> {% endfor %}
> }
>

I see, that's a pretty neat solution, I was also thinking about ajax
but didn't want the extra complexity.


>
> The above is raw and you need to refine it, taking into account which
> row in the form the widget should be rendered etc.
> In the ModelAdmin you then add extra media or you simply override the
> template and add the url for this dynamic javascript to the template.
> Take a look at contrib/gis/templates/gis/admin/openlayers.js for
> django-generated javascript inspiration.
>
>
I'll give it a try! Thanks Melvyn!



> --
> Melvyn Sopacua
>
> --
> 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.
>
>


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



Dynamic form field type.

2012-08-05 Thread Nicolas Emiliani
Hi,

Since what I was trying to do in this post : "Dynamic fieldsets on
ModelAdmin"
seems to be a dead end, and I'm running out of wild ideas, i'm going to
share
with u what I'm trying to do so you can maybe help me out.

I have three Models,

Home, HomeAttributeType and HomeAttributeValue. HomeAttributeValue has
an FK to HomeAttributeType and one to Home.

The idea is that the user can add as many HomeAttributeTypes as he wants and
set the data type of the former. ie :

ha1 = HomeAttributeType
ha1.name = 'FooAttr2'
ha1.type = 'boolean'

ha2 = HomeAttributeType
ha2.name = 'FooAttr2'
ha2.type = 'numeric'

So, now the user when creating a Home through a ModelAdmin, has the Admin
for the HomeAttributeValue inlined, and so he can set, for example, for
that home
a FooAttr1 selecting in from the Drop Down menu.

And here comes the black magic, If he selects FooAttr1 the value field for
the HomeAttributeValue
should render itself as radio button (yes/no) and if it where FooAttr2 it
should render itself as
an InputText. I can easily do this with JS, but what I can't do is to
somehow add a bunch
of hidden inputs that can relate each HomeAttributeType to what they should
render to.

Since I have a variable number of HomeAttributeTypes, I need to set a
variable number of
hidden fields in the form. I was reading about FormSets but I can't find
the way to add one
to the ModelForm that the  HomeAdmin is using.

Any help, hints, or even curses will be appreciated.

Thanks.

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: dynamic fildsets on ModelAdmin

2012-08-05 Thread Nicolas Emiliani
On Sun, Aug 5, 2012 at 5:40 PM, Melvyn Sopacua <m.r.sopa...@gmail.com>wrote:

> On 5-8-2012 20:16, Nicolas Emiliani wrote:
> > Hi, I've been struggling with dynamic forms and until now I'm loosing the
> > battle :S
>
> > So, now I want the HomeAdmin to render all this stuff into the from, but
> > when I try to
> > add this fields into the fieldset attribute and load the page it fails
> > saying.
>
> Sorry to say this, but you have to go back to the drawing board. You
> cannot add random fields to fieldset. They *have* to be models.Field
> classes of the model attached the ModelAdmin so that the values get
> cleaned properly.
> If you want extra fields for the form, you do this via inlines for
> related objects or you subclass a ModelForm and set the form attribute
> of the ModelAdmin.
>
>
Ups. Well, thanks anyways. Since my drawing board is full of drawings,
and they are not happy faces, I'll create another post with what I want
to accomplish and maybe you can suggest something.



> --
> Melvyn Sopacua
>
> --
> 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.
>
>


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



dynamic fildsets on ModelAdmin

2012-08-05 Thread Nicolas Emiliani
Hi, I've been struggling with dynamic forms and until now I'm loosing the
battle :S
The thing is that I have a HomeAdmin(ModelAdmin) that uses the form
HomeAdminForm(ModelForm)

The HomeAdminForm redefines the __init__ method to add a bunch a of hidden
input fields like this :

class HomeAdminForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
super(HomeAdminForm, self).__init__(*args, **kwargs)
#add all the attribute types
for at in HomeAttrType.objects.all():
self.fields['attr_type_%s' % at.name] = forms.CharField(
 widget=forms.HiddenInput(attrs={'class': 'hidden'}),
label='', bound=True)


So, now I want the HomeAdmin to render all this stuff into the from, but
when I try to
add this fields into the fieldset attribute and load the page it fails
saying.

Unknown field(s) (attr_type_foo, attr_type_prueba, attr_type_carnasa)
specified for Home


Those fields are the ones I added at HomeAdminForm.__init__ this way

class HomeAdmin(admin.ModelAdmin):

form = HomeAdminForm

def __init__(self, *args, **kwargs):
super(HomeAdmin, self).__init__(*args, **kwargs)
hidden_fields = []
for at in HomeAttrType.objects.all():
hidden_fields.append('attr_type_%s' % at.name)
self.fieldsets.append((None, {'fields' : hidden_fields, }))

The problem seems to be that the constructor for HomeAdminForm gets called
after
the constructor for HomeAdmin, so all the added fields are not there yet
when
HomeAdmin.__init__ is called.

Is what I'm trying do ok ?,  Is there any way to fix this ?

Thanks dudes,

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: access the state of a Model object prior to it's modification ?

2012-07-31 Thread Nicolas Emiliani
On Mon, Jul 30, 2012 at 6:22 PM, Tomas Neme <lacrymol...@gmail.com> wrote:

>
> uhm, if you register a listener to the pre_save signal, then you can do
> this:
>
>
> if instance.published:
>   # the instance about to be saved has the published flag on
>   dbojb = MyModel.objects.get(id=instance.id)
>
>   # did it have it on the database?
>   if not dbobj.published:
> do_stuff()
>
> you probably need to check the "created" argument on the listener that
> tells you if the object is a new one, or a modification
>
>
Great! ... this is what I was looking for. Signals is what I meant by
"the django way of .."

Thanks all!



> --
> "The whole of Japan is pure invention. There is no such country, there are
> no such people" --Oscar Wilde
>
> |_|0|_|
> |_|_|0|
> |0|0|0|
>
> (\__/)
> (='.'=)This is Bunny. Copy and paste bunny
> (")_(") to help him gain world domination.
>
>  --
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: Dynamic forms

2012-07-30 Thread Nicolas Emiliani
On Mon, Jul 30, 2012 at 4:53 PM, Sandeep kaur <mkaurkha...@gmail.com> wrote:

> I want to have a form, with drop down list and then multiple select
> checkboxes dynamically filtered based on drop down selection. I have
> searched a lot but did not find a complete solution for my
> requirement. Also I want to ask that can we do this without apply java
> query ?  Means if a browser doesn't support java, how would our could
> run?
>

Well, I just did something alike, where I basically have three dropdowns
that are related , when you pick something in the first one, the others
load
up some different options.

The way i did it was attaching the change event using jQuery to the rendered
dropdown and the working my way from there. I don't know if it is the most
solid/clean way to do it, but it works. I wouldn't know how to do that
without js.



>
> Help would be really appreciated.
> Thank you.
>
> --
> Sandeep Kaur
> E-Mail: mkaurkha...@gmail.com
> Blog: sandymadaan.wordpress.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.
>
>


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: access the state of a Model object prior to it's modification ?

2012-07-30 Thread Nicolas Emiliani
This is a long shot but try checking out django-reversion
>

Sounds interesting.


> thank you.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/NM39pkUyvG4J.
>
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: Overriding save to create and save related entity

2012-07-25 Thread Nicolas Emiliani
On Wed, Jul 25, 2012 at 12:34 PM, Sithembewena Lloyd Dube <zebr...@gmail.com
> wrote:

> Hi all,
>
> I have the following code:
>
> class Points(models.Model):
>  blah blah
>
> class TrainingSession(models.Model):
> confirmed = models.BooleanField()
> points = models.ForeignKey(Points, null=True, blank=True)
>
> When a training session is saved, if confirmed is True I wish to create
> and save a points instance. How can I do so?
>

You can override the save_model method at the ModelAdmin

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model


>
> --
> Regards,
> Sithembewena Lloyd Dube
>
> --
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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_add TabularInline ?

2012-07-21 Thread Nicolas Emiliani
Hi,

so.. I have a TabularInline admin view that displays '+ Add another' and I
would
like to remove it, like can_delete = False but for the add option. sadly
can_add
doesn't exist, so how do I achieve this ?

Thanks!

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: unable to override widget

2012-07-17 Thread Nicolas Emiliani


On Sunday, July 15, 2012 6:16:42 PM UTC-3, Nicolas Emiliani wrote:
>
> Crap, hit the send key, there it goes. Sorry.
>
>
> Hi!
>>
>> I'm trying to override the AdminFileWidget with no success. The idea is 
>> to get a thumbnail
>> next to the uploaded files in a tabular view of the admin site. I did the 
>> following :
>>
>>

Just in case somebody reads this : I fxed it, it was working, but an 
exception inside the 
render method made the output look like the parent widget :S

 

> class AdminImageWidget(AdminFileWidget):
>> def render(self, name, value, attrs=None):
>>
>>
> Override the widget class for the image field
>
> class ImageGalleryForm(forms.ModelForm):
> '''
> Image Admin form
> '''
> class Meta:
> model = HomeImage
> fields =('image','description','name','height','width',) 
> widgets = {
> 'image' : AdminImageWidget,
> }
>
>
> Here I set the Form
>
> class ImageGaleryInline(admin.TabularInline):
> form = ImageGalleryForm
> model = HomeImage
> extra = 3
>
> fieldsets = [
> (None, {
> 'fields' : [
> ('image','description','name','height','width'),
> ]
>     }
> ),
> ]
>
>
> But the widget still shows itself as the AdminFileWidget, Am I missing 
> something ?
>
> Thanks
>
>  
>
>>
>> -- 
>> Nicolas Emiliani
>>
>> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>>  
>
>
>
> -- 
> Nicolas Emiliani
>
> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/yRdMHbeK95wJ.
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 am I getting an error when send e-mail from hosting?

2012-07-16 Thread Nicolas Emiliani
On Mon, Jul 16, 2012 at 4:05 AM, Andrejus <andrius.momzya...@gmail.com>wrote:

> I've got a Django instance (1.4, python 2.7.2) running via FastCGI on
> vds-hosting.
> The problem is:
>
> (mypython)-bash-4.1$ python manage.py shell
> Python 2.7.2 (default, Dec  8 2011, 12:06:29)
> [GCC 4.4.4 20100726 (Red Hat 4.4.4-13)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
> >>> import django
> >>> from django.core.mail import EmailMessage
> >>> email = EmailMessage('Hello', 'World', to=['bla-...@bla-bla.ru'])
> >>> email.send()
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/home/vhosts/
> e-pyfan.com/private/mypython/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/mail/message.py",
> line 248, in send
> return self.get_connection(fail_silently).send_messages([self])
>   File "/home/vhosts/
> e-pyfan.com/private/mypython/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/mail/backends/smtp.py",
> line 92, in send_messages
> sent = self._send(message)
>   File "/home/vhosts/
> e-pyfan.com/private/mypython/lib/python2.7/site-packages/Django-1.4-py2.7.egg/django/core/mail/backends/smtp.py",
> line 110, in _send
> email_message.message().as_string())
>   File "/opt/python27/lib/python2.7/smtplib.py", line 728, in sendmail
> raise SMTPDataError(code, resp)
> SMTPDataError: (554, 'mail server permanently rejected message (#5.3.0)')
>

I would check a few things, first :

What smtp server are you using ?
Did you configured your django app to use the SMTP server?, I think you
need to add some SMTP_ vars to your settings.py,
because otherwise you will end up using sendmail (if it's linux) and it
might be shutoff for security reasons.

If you have an SMTP server in your hosting access it using TELNET and try
to send an email through the CLI interface
to check that it works correctly.

Hope it helps.



>
> When I tested e-mail sending on my PC with locally installed mail server I
> didn't have any problem, mailing worked well.
> Please anybody help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/pI8qXk50AaEJ.
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: access the state of a Model object prior to it's modification ?

2012-07-16 Thread Nicolas Emiliani
Jani, thanks for the idea, some thoughts below your code.


>
> class MyPublicationModel(Model):
> def save(...):  # I don't remember the signature
> if self.is_published and not self.publication_date:
> # Published previously unpublished - set the date
> self.publication_date = date.today()
>elif not self.is_published and self.publication_date:
> # Mark already published as unpublished - clear the date
> self.publication_date = None
>
>super(self, MyPublicationModel).save(...)
>
>
Yes, you are right, but you are clearing the date, the thing
is that I don't want to clear it. That's why I thought of having
an attribute in the model that does not render in the form,
that would allow me to keep the previous state unchanged
and use that in my logic.


> On Mon, Jul 16, 2012 at 3:39 AM, Nicolas Emiliani <or3s...@gmail.com>wrote:
>
>>
>>
>> On Sun, Jul 15, 2012 at 8:10 PM, Jani Tiainen <rede...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> How about telling us what are you trying to achieve by comparing to
>>> previous state of the object?
>>>
>>>
>> Well, the model has a boolean field called published, and a publish_date
>> that gets set "automatically"
>> when the user through the admin panel sets the flag published to true. He
>> could also unpublish it, but the
>> date would still remain the same (on the date it was first published).
>> And here comes the problem :
>>
>> If the user decides to republish I would have to set the date to current
>> date, but how do I know if he
>> is republishing or he modified some other field that has nothing to do
>> with that attribute ? I would be
>> republishing only if it's previous state was not published. But how can I
>> acces that previous state ?
>>
>> Sounds waky :P
>>
>>
>>
>>> On Sun, Jul 15, 2012 at 1:49 AM, Nicolas Emiliani <or3s...@gmail.com>wrote:
>>>
>>>> Hi,
>>>>
>>>> Is there a way to access the state of a Model object prior to it's
>>>> modification through a form ?
>>>> Kind of a nasty question :S, let me explain.
>>>>
>>>> The thing is that if i use the save_model hook and the user modifies
>>>> the model through the form,
>>>> the obj parameter that I receive has already all the modifications
>>>> loaded, so if  I have, let's say,
>>>> a boolean attribute called "published"  and the user clicked published
>>>> then :
>>>>
>>>> obj.published == True
>>>>
>>>> Is there a way to know which was the state of the model, in this case
>>>> the state of obj.published,
>>>> before the user clicked on the save button on the admin form ? or
>>>> should I use a second model
>>>> attribute and hide it on the form to keep the previous state ? is there
>>>> a "Django" way to do this ?
>>>>
>>>> It's my first post, be gentle :P
>>>>
>>>> Thanks !
>>>>
>>>> --
>>>> Nicolas Emiliani
>>>>
>>>> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>>>>
>>>> --
>>>> 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.
>>>>
>>>
>>>
>>>
>>> --
>>> Jani Tiainen
>>>
>>> - Well planned is half done, and a half done has been sufficient
>>> before...
>>>
>>>  --
>>> 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.
>>>
>>
>>
>>
>> --
>> Nicolas Emiliani
>>
>> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>>
>> --
>> You received this message because you are subscrib

Re: access the state of a Model object prior to it's modification ?

2012-07-15 Thread Nicolas Emiliani
On Sun, Jul 15, 2012 at 8:10 PM, Jani Tiainen <rede...@gmail.com> wrote:

> Hi,
>
> How about telling us what are you trying to achieve by comparing to
> previous state of the object?
>
>
Well, the model has a boolean field called published, and a publish_date
that gets set "automatically"
when the user through the admin panel sets the flag published to true. He
could also unpublish it, but the
date would still remain the same (on the date it was first published). And
here comes the problem :

If the user decides to republish I would have to set the date to current
date, but how do I know if he
is republishing or he modified some other field that has nothing to do with
that attribute ? I would be
republishing only if it's previous state was not published. But how can I
acces that previous state ?

Sounds waky :P



> On Sun, Jul 15, 2012 at 1:49 AM, Nicolas Emiliani <or3s...@gmail.com>wrote:
>
>> Hi,
>>
>> Is there a way to access the state of a Model object prior to it's
>> modification through a form ?
>> Kind of a nasty question :S, let me explain.
>>
>> The thing is that if i use the save_model hook and the user modifies the
>> model through the form,
>> the obj parameter that I receive has already all the modifications
>> loaded, so if  I have, let's say,
>> a boolean attribute called "published"  and the user clicked published
>> then :
>>
>> obj.published == True
>>
>> Is there a way to know which was the state of the model, in this case the
>> state of obj.published,
>> before the user clicked on the save button on the admin form ? or should
>> I use a second model
>> attribute and hide it on the form to keep the previous state ? is there a
>> "Django" way to do this ?
>>
>> It's my first post, be gentle :P
>>
>> Thanks !
>>
>> --
>> Nicolas Emiliani
>>
>> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>>
>> --
>> 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.
>>
>
>
>
> --
> Jani Tiainen
>
> - Well planned is half done, and a half done has been sufficient before...
>
>  --
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: unable to override widget

2012-07-15 Thread Nicolas Emiliani
Crap, hit the send key, there it goes. Sorry.


Hi!
>
> I'm trying to override the AdminFileWidget with no success. The idea is to
> get a thumbnail
> next to the uploaded files in a tabular view of the admin site. I did the
> following :
>
> class AdminImageWidget(AdminFileWidget):
> def render(self, name, value, attrs=None):
>
>
Override the widget class for the image field

class ImageGalleryForm(forms.ModelForm):
'''
Image Admin form
'''
class Meta:
model = HomeImage
fields =('image','description','name','height','width',)
widgets = {
'image' : AdminImageWidget,
}


Here I set the Form

class ImageGaleryInline(admin.TabularInline):
form = ImageGalleryForm
model = HomeImage
extra = 3

fieldsets = [
(None, {
'fields' : [
('image','description','name','height','width'),
]
}
),
]


But the widget still shows itself as the AdminFileWidget, Am I missing
something ?

Thanks



>
> --
> Nicolas Emiliani
>
> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



unable to override widget

2012-07-15 Thread Nicolas Emiliani
Hi!

I'm trying to override the AdminFileWidget with no success. The idea is to
get a thumbnail
next to the uploaded files in a tabular view of the admin site. I did the
following :

class AdminImageWidget(AdminFileWidget):
def render(self, name, value, attrs=None):


-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

-- 
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: Query Distance from User

2012-07-15 Thread Nicolas Emiliani


What you have just explained seems to be a good option! Is the option to 
> use latitude and longitude a very common one? I'm not 
> as familiar as to which options of calculation have known to be the most 
> stable, usable, fast, or efficient. Or there is any common
> knowledge about the such thing.
>

Well with (lat, long) you can point to any place on earth, it's like having 
an (x,y) point on a cartesian plane. 
And yes, it is the standard method.
 

>
> Here's what I'm thinking. First the user enters their town for example so 
> Vienna, VA. Then they choose how far from their location so 25 miles. But 
> then they also have an advanced search option where they can refine their 
> request even more. They are able to play around with a Google Map on the 
> side and zoom into their physical house location on the map and put a 
> marker/point there of some sort. This could be lat/long I don't know yet. 
> This way if that data checks out they get and even more accurate 
> representation of the artists in their area. Any thoughts or opinions on 
> how you think I
> should go about this?
>
>
With the (lat,long) that belongs to the user position yo can then ask for a 
radius in blocks, meters o whatever.
So, now you can get the surface of a circle and with some basic math you go 
through your db checking if any artist
are inside the limit of that circle.
 

> Thanks so much! 
>
> JJ 
>
> On Sunday, July 15, 2012 10:22:53 AM UTC-4, Nicolas Emiliani wrote:
>>
>>
>>
>> On Sun, Jul 15, 2012 at 1:58 AM, JJ Zolper <codinga...@gmail.com> wrote:
>>
>>> So heres my goal:
>>>
>>> The user logins in and goes to a discover page. They enter a distance 
>>> from their location as the requested results scope. Lets say 25 miles from 
>>> where I live for example. Additionally they could pick like a genre or 
>>> music but not as important.
>>>
>>> So they hit seach and see in a 25 mile spanse in all directions in a 
>>> circle form the closest artists to their location. From there they can see 
>>> the top result and click that and step through the top results from 1 to 2 
>>> to 3 To top 10 and so on as much as their heart desires.
>>>
>>> So i was thinking maybe GeoIP might be good because it will use the 
>>> users location and last known GeoIP of the artist for example.
>>>
>>>
>> I'm currently developing a project based on google maps, and it sounds 
>> that you might want to take a look at their API,
>> You could use markers (latitude and longitude) for your artists, ask the 
>> user to place themselves on the map and then
>> calculate if they are on the wanted area or not.
>>  
>> https://developers.google.com/maps/
>>
>> I was curious if anyone had any ideas or better ideas then I had.
>>>
>>> Thanks so much,
>>>
>>> JJ Zolper
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msg/django-users/-/_ERIIZrolmUJ.
>>> 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.
>>>
>>
>>
>>
>> -- 
>> Nicolas Emiliani
>>
>> Lo unico instantaneo en la vida es el cafe, y es bien feo.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/tGFuC9PBd4kJ.
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: Query Distance from User

2012-07-15 Thread Nicolas Emiliani
On Sun, Jul 15, 2012 at 1:58 AM, JJ Zolper <codinga...@gmail.com> wrote:

> So heres my goal:
>
> The user logins in and goes to a discover page. They enter a distance from
> their location as the requested results scope. Lets say 25 miles from where
> I live for example. Additionally they could pick like a genre or music but
> not as important.
>
> So they hit seach and see in a 25 mile spanse in all directions in a
> circle form the closest artists to their location. From there they can see
> the top result and click that and step through the top results from 1 to 2
> to 3 To top 10 and so on as much as their heart desires.
>
> So i was thinking maybe GeoIP might be good because it will use the users
> location and last known GeoIP of the artist for example.
>
>
I'm currently developing a project based on google maps, and it sounds that
you might want to take a look at their API,
You could use markers (latitude and longitude) for your artists, ask the
user to place themselves on the map and then
calculate if they are on the wanted area or not.

https://developers.google.com/maps/

I was curious if anyone had any ideas or better ideas then I had.
>
> Thanks so much,
>
> JJ Zolper
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/_ERIIZrolmUJ.
> 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.
>



-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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



access the state of a Model object prior to it's modification ?

2012-07-14 Thread Nicolas Emiliani
Hi,

Is there a way to access the state of a Model object prior to it's
modification through a form ?
Kind of a nasty question :S, let me explain.

The thing is that if i use the save_model hook and the user modifies the
model through the form,
the obj parameter that I receive has already all the modifications loaded,
so if  I have, let's say,
a boolean attribute called "published"  and the user clicked published then
:

obj.published == True

Is there a way to know which was the state of the model, in this case the
state of obj.published,
before the user clicked on the save button on the admin form ? or should I
use a second model
attribute and hide it on the form to keep the previous state ? is there a
"Django" way to do this ?

It's my first post, be gentle :P

Thanks !

-- 
Nicolas Emiliani

Lo unico instantaneo en la vida es el cafe, y es bien feo.

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