Re: Restricting fields to certain users in admin

2009-05-19 Thread Matias Surdi

Matias Surdi escribió:
> I need to hide a couple fields from a model depending on the logged in 
> user in the admin interface.
> 
> How would you do this?
> 
> 
> > 
> 


Replying to myself, here is the solution:



class LimitedCustomUserAdmin(UserAdmin):
 inlines = [ProfileAdmin]
 form = forms.CustomUserChangeForm
 fieldsets = (
 (None, {'fields': ('username', 'password')}),
 ('Personal info', {'fields': ('first_name', 'last_name', 
'email')}),
 ('Permissions', {'fields': ('is_staff', 'is_active', 
'is_superuser')}),
 ('Important dates', {'fields': ('last_login', 'date_joined')}),
 ('Groups', {'fields': ('groups',)}),
 )



class CustomUserAdmin(LimitedCustomUserAdmin):
 fieldsets = (
 (None, {'fields': ('username', 'password')}),
 ('Personal info', {'fields': ('first_name', 'last_name', 
'email')}),
 ('Permissions', {'fields': ('is_staff', 'is_active', 
'is_superuser', 'user_permissions')}),
 ('Important dates', {'fields': ('last_login', 'date_joined')}),
 ('Groups', {'fields': ('groups',)}),
 )
 def __init__(self,*args,**kwargs):
 CustomUserAdmin.limited_user_admin = 
LimitedCustomUserAdmin(*args,**kwargs)
 return super(CustomUserAdmin,self).__init__(*args,**kwargs)

 def __call__(self, *args, **kwargs):
 if get_current_user().is_superuser:
 return super(CustomUserAdmin, self).__call__(*args, **kwargs)
 else:
 return CustomUserAdmin.limited_user_admin(*args,**kwargs)



This way, super_users can view/edit the fields defined in 
CustomUserAdmin and non super_users can view/edit the fields on 
LimitedCustomUserAdmin.


Note: You've to register only CustomUserAdmin with the User model.







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



Restricting fields to certain users in admin

2009-05-19 Thread Matias Surdi

I need to hide a couple fields from a model depending on the logged in 
user in the admin interface.

How would you do this?


--~--~-~--~~~---~--~~
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: Javascript Framework``

2009-05-13 Thread Matias Surdi

Ramdas S escribió:
> everything goes well with django.
> 
> 
> 
> On Wed, May 13, 2009 at 11:10 PM, Guri  > wrote:
> 
> 
> Hi,
>   I need some help regarding which javascript framework will go
> well with Django and is better in terms of documentation, easy to use
> and preferred.
> Couple of them I know:
> 1. Dojo with dijit themes
> 2. Scriptaculous
> 3... any other...
> 
> Thanks in Advance
> ~Guri
> 
> 
> 
> 
> 
> -- 
> Ramdas S
> +91 9342 583 065
> 
> 
> > 

Django is compatible with all javascript frameworks. Personally, I 
prefer JQuery.

Matias.


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



Auto populate ModelAdmin

2009-05-12 Thread Matias Surdi

I've noticed that on the admin interface, if a model has for example a 
"name" attribute, if I access to the add form with an url like this:

http://localhost:8000/admin/mymodel/add?name=something

The name field is prepopulated with the parameter value.

Is this behaviour documented somewhere?

Is it possible to prepopulate this way inlines for the model?


Thanks a lot.


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

2009-04-29 Thread Matias Surdi

tdelam escribió:
> Hi Guys,
> 
> This might get lengthy but I am trying to get some insight on the best
> way to generate some dynamic forms in a template. The project is a
> survey. Here is my questions model:
> 
> class Question(models.Model):
>   TRUEFALSE = 1 # a radio button yes/no question
>   MULTIPLEANSWER = 2 # checkbox question
>   SINGLEANSWER = 3 # radio button answer
>   COMMENT = 4 # textarea box for comments
> 
>   QUESTION_CHOICES = (
>   (TRUEFALSE, 'Yes/No question'),
>   (MULTIPLEANSWER, 'Multiple answer question'),
>   (SINGLEANSWER, 'Single answer'),
>   (COMMENT, 'Comment box')
>   )
> 
>   question_type = models.IntegerField(choices=QUESTION_CHOICES,
> default=TRUEFALSE)
>   survey = models.ForeignKey(Survey)
>   title = models.CharField(max_length=250)
> 
>   def __unicode__(self):
>   return self.title
> 
> Questions are built using the django admin and they can select the
> type of question it will be via the QUESTION_CHOICES. In my template I
> am testing for the type of question but I want to display the proper
> form fields for this question. So, a True/False will be radio widget,
> multiple answer will be checkbox and so on, I will need to do this
> dynamically of course so i can show the question with the widget type
> from the constants in my model. How can I do this?
> 
> Currently I have something somewhat working...  :
> 
> class TrueFalseForm(forms.Form):
>   def __init__(self, questions, *args, **kwargs):
>   super(TrueFalseForm, self).__init__(*args, **kwargs)
>   for i, question in enumerate(questions):
>   self.fields['answer'] = 
> forms.ChoiceField(widget=forms.RadioSelect
> (), choices=[['%d % i', question]], label=question)
> 
> 
> Any suggestions would be much appreciated.
> > 
> 


Have you already read this?

http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/




--~--~-~--~~~---~--~~
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 way to pass parameters to templates

2009-03-25 Thread Matias Surdi

Which is the correct or recommended way to accomplish what is described 
in the following url with django?

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



My question is, if I have a template like this:

{% for i in args %}{{ i }}{% endfor %}
{{ title }}
{{ name }}
args
{{ args }}
kwargs
{{ kwargs }}


I'd like to "include" it from several places but with different values 
for the variables each time.


Thanks a lot.


--~--~-~--~~~---~--~~
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?[Newbie]

2009-03-05 Thread Matias Surdi

Hi Andrews,

Look at this:

http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/

This helped me a lot a couple months ago when I had to do some dynamic 
forms. Those forms where generated from data entered by the user in a 
previous step.


It can be a bit "messy" if you don't take care, but works.

andrew wrote:
> Hi , Dear all:
> 
> I had searched this forum but with limit information about dynamic
> forms .
> 
>Model:
> -
> class Product(models.Model):
>   name = models.CharField(max_length=30) # Product Name
> type = models.IntegerField(max_length=30)# Type ID
> 
>  I want to create a certain type product list form for visitor to
> choice one and submit.
> the Product table may continuously changed .
> 
> So how can I create a list in the form?
> 
> Any Suggestions and Reference links will be highly appreciated!
> > 
> 


--~--~-~--~~~---~--~~
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: Announcing Django Noob Group

2009-02-19 Thread Matias Surdi

I don't think it is really needed.

I think this list is perfectly OK for newbies and advanced users.There 
is not a clear line defining when you are a newbie and when you are an 
average user as well.

Now, we must search two archives instead of just a centralized one.



Bobby Roberts wrote:
> ... simpleton questions welcome, mentors encouraged to help...
> 
> http://groups.google.com/group/djangonoobs
> > 
> 


--~--~-~--~~~---~--~~
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: Problems with authentication login/logout

2009-01-28 Thread Matias Surdi

Matias Surdi escribió:
> I've followed the documentation on users authentication and it's working 
> fine except for one thing.
> 
> When a user logs out from the public views, it is also logged out from 
> the admin site and when the user logs in in the public view, if it has 
> staff permission it can access the admin site.So far, so good. *The 
> problem is that when the user logs in directly to the admin interface is 
> not being logged in into the public views*.
> 
> What could be happening here?
> 
> Thanks for any idea.
> 
> 
> > 
> 


Ignore this.
Sorry.


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



Problems with authentication login/logout

2009-01-28 Thread Matias Surdi

I've followed the documentation on users authentication and it's working 
fine except for one thing.

When a user logs out from the public views, it is also logged out from 
the admin site and when the user logs in in the public view, if it has 
staff permission it can access the admin site.So far, so good. *The 
problem is that when the user logs in directly to the admin interface is 
not being logged in into the public views*.

What could be happening here?

Thanks for any idea.


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



About django validation system

2009-01-28 Thread Matias Surdi

Shouldn't validation be defined in the modell instead of the forms?


Suppose I've a Model wich has some restrictions on the value a field can 
get, and then I've a custom form for this model for the admin interface 
and two other forms for the public interface.

Does this mean that I've to define my validation rules three times?

What is the logic behind  this?

Where is the correct place to code these custom validation rules in this 
scenario?

Should I post this message to django-devel?

What is the meaning of life? (well, you can ignore this last one :-) )

Thank you very much.


--~--~-~--~~~---~--~~
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: Basic question: hidden input not working

2009-01-26 Thread Matias Surdi

forget it, I've found the solution:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#exclude



Sorry...


Matias Surdi escribió:
> What is wrong with the following code?
> 
> class IPAddressAdminForm(forms.ModelForm):
>  notification_sent = 
> forms.BooleanField(widget=forms.widgets.HiddenInput,required=False)
>  class Meta:
>  model = IPAddress
> 
> 
> class IPAddress(BaseModel):
>  network = models.ForeignKey(Network)
>  ip = models.IPAddressField()
>  user = models.ForeignKey(User,blank=True,null=True)
>  registered = models.DateTimeField(blank=True,null=True)
>  renewed = models.DateTimeField(blank=True,null=True)
>  expires = models.DateTimeField(blank=True,null=True)
>  notification_sent = models.BooleanField(default=False)
> 
> 
> Despite the widget of notification_sent is set to HiddenInput, the label 
> for the boolean field is still rendered in the admin.
> 
> Many thanks for your help
> 
> 
> > 
> 


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



Basic question: hidden input not working

2009-01-26 Thread Matias Surdi

What is wrong with the following code?

class IPAddressAdminForm(forms.ModelForm):
 notification_sent = 
forms.BooleanField(widget=forms.widgets.HiddenInput,required=False)
 class Meta:
 model = IPAddress


class IPAddress(BaseModel):
 network = models.ForeignKey(Network)
 ip = models.IPAddressField()
 user = models.ForeignKey(User,blank=True,null=True)
 registered = models.DateTimeField(blank=True,null=True)
 renewed = models.DateTimeField(blank=True,null=True)
 expires = models.DateTimeField(blank=True,null=True)
 notification_sent = models.BooleanField(default=False)


Despite the widget of notification_sent is set to HiddenInput, the label 
for the boolean field is still rendered in the admin.

Many thanks for your help


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



Re: Raw SQL parameters

2009-01-19 Thread Matias Surdi

Karen Tracey escribió:
> On Mon, Jan 19, 2009 at 2:06 PM, Matias Surdi <matiassu...@gmail.com 
> <mailto:matiassu...@gmail.com>> wrote:
> 
> Yes, maybe it's just a problem with sqlite, which is te backend I'm
> using.I'll try with mysql later.
> 
> Is this a bug? should it be reported as a ticket?
> 
> 
> I see you opened ticket #10070, which is fine because I don't know the 
> answer to whether it is a bug that some of the backends do not support 
> this style of parameter passing.  Django apparently doesn't use it 
> internally, nor document support for it 
> (http://docs.djangoproject.com/en/dev/topics/db/sql/ doesn't mention it) 
> so it may be permissible variation in the backends, I don't know.  
> Hopefully someone who knows more than I will respond in that ticket.
> 
> Karen
> 
> > 


Many thanks for your help.


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



Re: Raw SQL parameters

2009-01-19 Thread Matias Surdi

Karen Tracey escribió:
> On Mon, Jan 19, 2009 at 12:40 PM, Ramiro Morales <cra...@gmail.com 
> <mailto:cra...@gmail.com>> wrote:
> 
> 
> On Mon, Jan 19, 2009 at 3:15 PM, Matias Surdi <matiassu...@gmail.com
> <mailto:matiassu...@gmail.com>> wrote:
>  >
>  > The curious thing here, is that the above query works perfect
> running it
>  > directly through sqlite3.
>  >
> 
>  From what I have seen by reading DB backend source code, Django
> cursor's
> execute() method supports only the printf-like parmeter maker style
> with a list
> or tuple of actual parameters.
> 
> If you want to use the pyformat parameter marking style (as described
> in PEP 249),
> you' ll need to use the native DB-API driver API as you've already
> discovered.
> 
> 
> I didn't look at any code, I just tried a similar query on my own DB, 
> using current 1.0.X branch code:
> 
> k...@lbox:~/software/web/xword$ python manage.py shell
> Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40)
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
>  >>> from django.db import connection
>  >>> query = "SELECT * FROM Authors WHERE Author = %(name)s"
>  >>> parms = {'name': 'Manny Nosowsky'}
>  >>> cursor = connection.cursor()
>  >>> data = cursor.execute(query, parms)
>  >>> data
> 1L
>  >>> cursor.fetchall()
> ((4L, u'Manny Nosowsky', u'No', u''),)
>  >>>
>  >>>
> 
> That's using MySQL as the DB, so perhaps it is backend-specific?  The 
> only thing I needed to do to make the example shown originally work is 
> remove the quotes (and use table/column/parm names that exist in my DB).
> 
> Karen
> 
> > 


Yes, maybe it's just a problem with sqlite, which is te backend I'm 
using.I'll try with mysql later.

Is this a bug? should it be reported as a ticket?




--~--~-~--~~~---~--~~
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: Raw SQL parameters

2009-01-19 Thread Matias Surdi

Karen Tracey escribió:
> On Mon, Jan 19, 2009 at 11:49 AM, Matias Surdi <matiassu...@gmail.com 
> <mailto:matiassu...@gmail.com>> wrote:
> 
> 
> Hi,
> 
> 
> I'm trying to run a sql query with parameters taken from a dict, here is
> the relevant part of the code:
>query = "select * from table where name='%(name)s'"
> 
> 
> Remove the single quotes around '%(name)s'.  The backend will handle 
> quoting, I expect the extra quotes are causing confusion somewhere.
> 
> Karen
>  
> 
> 
>parameters = {'name':'valueofname'}
> cursor = connection.cursor()
> data = cursor.execute(query,parameters)
> 
> 
> The error I get is:
> 
> TypeError: format requires a mapping
> 
> 
> But, as far as I know (from PEP249) this should be possible.
> Basically, what I need, is to pass the parameters values in a dict, and
> not as a list or tuple as is shown in django docs.
> 
> Which is the correct way to accomplish this?
> 
> Thanks a lot.
> 
> 
> > 



Sorry, these quotes are a typo, the running code doesn't have them.

I've also tried with:

cursor.execute("select * from table where 
field=:value",{'value':'something'})

And I got the error:
"Type error: not all arguments converted during string formatting"


The curious thing here, is that the above query works perfect running it 
directly through sqlite3.



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



Raw SQL parameters

2009-01-19 Thread Matias Surdi

Hi,


I'm trying to run a sql query with parameters taken from a dict, here is 
the relevant part of the code:
query = "select * from table where name='%(name)s'"
parameters = {'name':'valueofname'}
 cursor = connection.cursor()
 data = cursor.execute(query,parameters)


The error I get is:

TypeError: format requires a mapping


But, as far as I know (from PEP249) this should be possible.
Basically, what I need, is to pass the parameters values in a dict, and 
not as a list or tuple as is shown in django docs.

Which is the correct way to accomplish this?

Thanks a lot.


--~--~-~--~~~---~--~~
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 in admin interface

2009-01-13 Thread Matias Surdi

Daniel Roseman escribió:
> On Jan 12, 5:38 pm, Matias Surdi <matiassu...@gmail.com> wrote:
>> Hi,
>>
>> I've two models related by a ForeignKey field.
>>
>> I'd like to have the possibility of adding child objects (side "One" of
>> the relation) from the admin interface of the parent ("Many" side of the
>> relation).
>>
>> Example:
>>
>> class Child(models.Model):
>> name = models.CharField(max_length=10)
>>
>> class Parent(models.Model):
>>name = models.CharField(max_length=10)
>>childs = models.ForeignKey(Child)
>>
>> In this example, a dropdown is shown on the admin that let's me choose
>> just one child or create another if the one I need doesn't exist.
>>
>> The point is, how can I have a list that lets me choose more than one
>> child and create them as needed?
>>
>> This is not a Many to Many relation, because every child belongs just to
>> one parent, but the widget I need is like the one from that kind of
>> relation in the admin interface (ie: Groups selection in the User edit
>> admin view).
>>
>> Thanks you very much.
> 
> You have the relationship the wrong way round. The ForeignKey belongs
> on the child, since presumably a child can only have one parent but a
> parent can have multiple children.
> 
> Once you've sorted that out, you can then use inline forms on the
> Parent admin to add multiple children to a single parent. See:
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects
> 
> --
> DR.
> > 
> 

hmm... Not really... from your point of view, think about this:  I want 
to edit the children from the parent admin view, and *not* assign 
parents to children from children's admin view

Do you see? the relation is the same, but from the other side.

I think I'm going to need a custom field/widget for this.

Thanks for your help.

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



ModelMultipleChoiceField in admin interface

2009-01-12 Thread Matias Surdi

Hi,

I've two models related by a ForeignKey field.

I'd like to have the possibility of adding child objects (side "One" of 
the relation) from the admin interface of the parent ("Many" side of the 
relation).

Example:

class Child(models.Model):
name = models.CharField(max_length=10)

class Parent(models.Model):
   name = models.CharField(max_length=10)
   childs = models.ForeignKey(Child)


In this example, a dropdown is shown on the admin that let's me choose 
just one child or create another if the one I need doesn't exist.

The point is, how can I have a list that lets me choose more than one 
child and create them as needed?

This is not a Many to Many relation, because every child belongs just to 
one parent, but the widget I need is like the one from that kind of 
relation in the admin interface (ie: Groups selection in the User edit 
admin view).


Thanks you very much.




--~--~-~--~~~---~--~~
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: Iterate over model database fields

2009-01-08 Thread Matias Surdi

Great!!

I think that the _meta attribute will be enough. I think that if I 
define a method on the base model of all my models something like 
get_fields() it could then return a list of the fields by accessing 
self._meta.fields, and this get_fields should be accessible from 
templates,shouldn't it?.

Thanks for your help :-)


bruno desthuilliers wrote:
> On 8 jan, 16:22, Matias Surdi <matiassu...@gmail.com> wrote:
>> Is there any way to iterate over all the fields in a model instance on a
>> template?
> 
> Not directly. The fields names are accessible thru the
> model_instance._meta attribute, and you cannot access '_protected'
> attributes in a template.
> 
>> I'd like to have a "default" template which iterates over whatever model
>> yo give it and prints all its field on a table.
> 
> You'll have to write a (simple) view that returns the model instance's
> fields names and values as context. But that's mostly trivial once you
> know how to get field names and values from an instance (which has
> already been explained here - but feel free to ask if you fail to find
> the relevant posts).
> 
> 
> > 
> 


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



Iterate over model database fields

2009-01-08 Thread Matias Surdi

Is there any way to iterate over all the fields in a model instance on a 
template?

I'd like to have a "default" template which iterates over whatever model 
yo give it and prints all its field on a table.


Any help will be appreciated.


--~--~-~--~~~---~--~~
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: best way to do tabs?

2009-01-08 Thread Matias Surdi

 > implement.  Just google YUI.
Shoudn't it have been "yahoo for YUI" ?

:-D


phoebebright escribió:
> I'm a great fan of YUI and they have some nice tabs that are easy to
> implement.  Just google YUI.
> 
> 
> On Jan 8, 10:03 am, Matias Surdi <matiassu...@gmail.com> wrote:
>> JQuery UI?
>>
>> Margie escribió:
>>
>>> Hi,
>>> This is not a directly a django question, but since django is the only
>>> web framework I know (and it's really cool, by the way!) I hope it's
>>> ok to post this here.
>>> Could someone advise me on the "best" way to do tabs?  IE, I'd like to
>>> have a set of tabs at the top of my page with a sub navigation bar
>>> below.  I am currently using a mechanism that I got from the pinax
>>> project - I use css similar to that in tabs.css, for those of you that
>>> know pinax.  That css controls how the html classes are set up when
>>> html is rendered for a particular tab, causing the tabs to look
>>> "pressed" at the appropriate times.
>>> I'm a newbie at web page design, so I don't have a good feeling for if
>>> this is the right direction to be pursing.  I find the css code and
>>> the way it interacts with site_base.html and base.html fairly
>>> confusing and hard to maintain, so I'm wondering if there is a better
>>> way.  Also (and more importantly) would like my tabs to be more
>>> dynamic.  For example, based on the user clicking on something, I
>>> would like to be able to add additional tabs.  It seems like using the
>>> css mechanism in pinax makes that very difficult, because the css for
>>> each tab has to be defined up front in order to get the shading right
>>> when you click on a tab.
>>> Can anyone advise me on what the best direction to go in is for having
>>> nice tabs that are easy to undrestand?
>>> I have not yet learned jquery or ajax, but they are on my list,
>>> perhaps those provide better frameworks than css?  Anyway, any
>>> pointers from those of you more experienced than me are appreciated!
>>> Margie
>>
> > 
> 


--~--~-~--~~~---~--~~
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: best way to do tabs?

2009-01-08 Thread Matias Surdi

JQuery UI?



Margie escribió:
> Hi,
> 
> This is not a directly a django question, but since django is the only
> web framework I know (and it's really cool, by the way!) I hope it's
> ok to post this here.
> 
> Could someone advise me on the "best" way to do tabs?  IE, I'd like to
> have a set of tabs at the top of my page with a sub navigation bar
> below.  I am currently using a mechanism that I got from the pinax
> project - I use css similar to that in tabs.css, for those of you that
> know pinax.  That css controls how the html classes are set up when
> html is rendered for a particular tab, causing the tabs to look
> "pressed" at the appropriate times.
> 
> I'm a newbie at web page design, so I don't have a good feeling for if
> this is the right direction to be pursing.  I find the css code and
> the way it interacts with site_base.html and base.html fairly
> confusing and hard to maintain, so I'm wondering if there is a better
> way.  Also (and more importantly) would like my tabs to be more
> dynamic.  For example, based on the user clicking on something, I
> would like to be able to add additional tabs.  It seems like using the
> css mechanism in pinax makes that very difficult, because the css for
> each tab has to be defined up front in order to get the shading right
> when you click on a tab.
> 
> Can anyone advise me on what the best direction to go in is for having
> nice tabs that are easy to undrestand?
> 
> I have not yet learned jquery or ajax, but they are on my list,
> perhaps those provide better frameworks than css?  Anyway, any
> pointers from those of you more experienced than me are appreciated!
> 
> Margie
> > 
> 


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



Run sql query as read only user

2009-01-05 Thread Matias Surdi

Hi,

For some reports, I need to allow the users to enter a sql query.It is 
required for this query (a sql SELECT) to be run as a read only database 
user.


Any idea how to implement this with django?


Thank you very much.


--~--~-~--~~~---~--~~
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: Are Dynamic fields possible?

2009-01-03 Thread Matias Surdi

I've done it, although it was not a trivial task.

This helped me a lot:

http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/



Xan wrote:
> Hi,
> 
> I just want to know if django support dynamic fields, that is the
> option of not specied the type of field in the model and that user
> could specify in application.
> 
> I think for examples about an application for doing notes. In one
> note, one want to have: title, body, media, etc. but the number of
> fields (and its type) is variable. What about something like:
> 
> class Note(models.Note):
> title = models.CharField(max_length=200)
> anything = models.ManyToManyField(DynamicField)
> 
> and when user create a class specifies title and adds want he/she
> wants (body, pictures, etc. with the type of the field).
> 
> Is it possible?
> Thanks a lot,
> Xan.
> 
> PS: Happy new year.
> > 
> 


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



custom field value representation

2009-01-03 Thread Matias Surdi

Hi,

Suppose I have the following model:

class Document(BaseModel):
 name = models.CharField(max_length=150,blank=True)
 description = models.TextField(blank=True)
 file = 
Models.FileField(upload_to="data/documentation/document/%Y/%m/%d",blank=True)


And suppose I've a model I created through the admin interface and 
uploaded a file named "document1.pdf"

Then, when modifying this database entry (in admin->change_form) I see 
the previous value as data/documentation/document/2009/01/03/document1.pdf"

Is there any way to get this value shown as just "document1.pdf" without 
the relative path?.. What i want, is to hide to the end user the 
filesystem location of the uploaded file.

I've accomplished this in the change_list by defining a custom method on 
the model that returns just the file name.

Thank you very much.


--~--~-~--~~~---~--~~
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: PDF creation!!!

2008-12-26 Thread Matias Surdi

I do the reports in HTML, using django templates and then instead of 
send the rendered result to the browser, I filter it throught htmldoc 
linux utility.

Works like a charm for me.


Abdel Bolanos Martinez wrote:
> Please can any one give me good references about tools for create PDF 
> reports, graphs in Django besides RepoLab
> 
> 
> thanks
> 
> 
> 
> 
> 
> Abdel Bolaños Martínez
> Ing. Infórmatico
> Telf. 266-8562
> 5to piso, oficina 526, Edificio Beijing, Miramar Trade Center. ETECSA
> 
> 
> > 

--~--~-~--~~~---~--~~
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: Model with 2 foreignkey to User

2008-12-24 Thread Matias Surdi

Maybe this helps:

http://www.b-list.org/weblog/2008/dec/24/admin/



Tirta K. Untario wrote:
> This is a continuation from my last question.
> 
> created_by  = models.ForeignKey(User)
> 
> I want to automatically use current logged in user as value. Can I put the 
> code inside def save(self) for this model? I can't find anything about 
> getting current user value from model.
> 
> Thanks in advance.
> 
> --Tirta
> -Original Message-
> From: "Tirta K. Untario" 
> 
> Date: Wed, 24 Dec 2008 01:39:20 
> To: 
> Subject: Model with 2 foreignkey to User
> 
> 
> 
> Hi all,
> 
> I'm developing a simple todo list. I use Django Auth for handling 
> authentication. This is my models.py
> 
> from django.contrib.auth.models import User
> class Item(models.Model):
> project = models.ForeignKey(Project)
> category= models.ForeignKey(Category)
> title   = models.CharField(max_length=250, unique=True) 
> priority= models.IntegerField(choices=PRIORITY_CHOICES, default=2) 
> completed   = models.BooleanField(default=False) 
> created_at  = models.DateTimeField(default=datetime.datetime.now) 
> created_by  = models.ForeignKey(User)
> assigned_to = models.ForeignKey(User)
> 
> I have 2 fields from Item model that I want to relate with User model: 
> 'created_by' and 'assigned_to'. This is the error message when I try to 
> syncdb:
> 
> Error: One or more models did not validate:
> todo.item: Accessor for field 'created_by' clashes with related field 
> 'User.item_set'. Add a related_name argument to the definition for 
> 'created_by'.
> todo.item: Accessor for field 'assigned_to' clashes with related field 
> 'User.item_set'. Add a related_name argument to the definition for 
> 'assigned_to'.
> 
> If I use only 1 foreignkey, it works without error, i.e:  created_by  = 
> models.ForeignKey(User) without  assigned_to  = models.ForeignKey(User)
> 
> Can anyone help me to solve this problem? TIA.
> 
> --Tirta
> 
> 
> 
> 
> > 


--~--~-~--~~~---~--~~
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: saving unicode data in file

2008-12-24 Thread Matias Surdi

Finally I've solved it with smart_str function.



Matias Surdi wrote:
> Hi, I'm trying to save on a FileField some generated data (a text file 
> obtained from a template):
> 
> The relevant code is:
> 
>  out = Template(open("/path/to/template").read())
>  context = Context({})
>  if request.POST["name"] != "":
>  name = request.POST["name"]
>  else:
>  name = "GeneratedDocument_%i" % obj.id
>  data = out.render(context)
>  obj.file.save("file",ContentFile(data))
> 
> 
> the problem arises with ContentFile(data), if data is just a string like 
> "a simple string" the everything is correct, but the actual data content 
> is an unicode string, so raw binary data is saved to the resulting file 
> instead of the actual text.
> 
> Simplifying, what I want is to save the output of a rendered template to 
> a FileField.
> 
> Any help will be very appreciated.
> 
> 
> Thanks a lot.
> 
> 
> > 
> 


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



saving unicode data in file

2008-12-23 Thread Matias Surdi

Hi, I'm trying to save on a FileField some generated data (a text file 
obtained from a template):

The relevant code is:

 out = Template(open("/path/to/template").read())
 context = Context({})
 if request.POST["name"] != "":
 name = request.POST["name"]
 else:
 name = "GeneratedDocument_%i" % obj.id
 data = out.render(context)
 obj.file.save("file",ContentFile(data))


the problem arises with ContentFile(data), if data is just a string like 
"a simple string" the everything is correct, but the actual data content 
is an unicode string, so raw binary data is saved to the resulting file 
instead of the actual text.

Simplifying, what I want is to save the output of a rendered template to 
a FileField.

Any help will be very appreciated.


Thanks a lot.


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



Best way to modify admin css

2008-11-27 Thread Matias Surdi

Hi,

Which is the best/recommended way to modify admin css ?

I know I can copy the admin templates to my templates dir and modify 
them as I wish, but that could be a problem in the future if these 
templates are updated in a new version and I want to switch to that version.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Two related select boxes, update the second depending on the first

2008-11-12 Thread Matias Surdi

This is exactly what I'm trying to do.

Thanks for your help.



Low Kian Seong escribió:
> Have a go with this:
> 
> 
> http://gtitsworth.blogspot.com/2007/07/chaining-selects-with-django-and-ajax.html
> 
> On Wed, Nov 12, 2008 at 3:54 AM, Matias Surdi <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I want to have on the admin interface a dropdown box and let the user
>> choose one of several options.Then, depending on this selection, update
>> (maybe through ajax) the values available on the second one.
>>
>>
>> Could anyone give me some guidelines or documentation about how is the
>> best way to do this?
>>
>>
>> Thanks a lot.
>>
>>
> 
> 
> 


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



Two related select boxes, update the second depending on the first

2008-11-11 Thread Matias Surdi

Hi,

I want to have on the admin interface a dropdown box and let the user 
choose one of several options.Then, depending on this selection, update 
(maybe through ajax) the values available on the second one.


Could anyone give me some guidelines or documentation about how is the 
best way to do this?


Thanks a lot.


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



Re: Date Format in Admin

2008-10-24 Thread Matias Surdi

http://docs.djangoproject.com/en/dev/ref/settings/#date-format

Botolph escribió:
> I would like to change the formatting of dates in the admin from -
> MM-DD to DD-MM-. I have set "DATE_FORMAT" in the settings file,
> but that only changes list_display and not the DateField input. In a
> post from Januar 2007 Adrian wrote:
> 
>> Yes, newforms DateFields let you specify the input format(s). This has
>> yet to be integrated into the Django admin, but it will be sooner
>> rather than later.
> 
> Has this been integrated now? If so, where can I change it? I have
> been searching for hours without finding a solution.
> 
> > 
> 


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



How to get the value of a form field within a template?

2008-10-10 Thread Matias Surdi

The same I do

{{form.interface.initial}}

I'd like to do something like

{{form.interface.value}}


How can I do this?


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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: what is the correct way to create a hidden form field?

2008-10-09 Thread Matias Surdi

Ignore it.
Solved
Matias Surdi escribió:
> I want to output an  
> 
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



what is the correct way to create a hidden form field?

2008-10-09 Thread Matias Surdi

I want to output an http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: ANNOUNCE: Django 1.0 released

2008-09-04 Thread Matias Surdi

James Bennett escribió:
> The Django team is pleased to announce the release of Django 1.0 this evening:
> 
> Download: http://www.djangoproject.com/download/
> Release notes: http://docs.djangoproject.com/en/dev/releases/1.0/
> 
> Have fun with it, and we'll see you in a few days for DjangoCon.
> 
> 

Many thanks you all for this excellent framework!. Cogratulations!


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



Django with non-sql database

2008-05-14 Thread Matias Surdi

Hi,

I'm trying to figure out how to use django models without an SQL-capable 
database. The database I'm trying to use are mainly simple plaint text 
configuration files.

I think the way to go is creating a custom manager. Is that correct?
Any better idea?

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



help with limit_choices_to

2008-05-08 Thread Matias Surdi

Hi.

I've the following model:

class ExamAttributeCalification(models.Model):
exam_result = models.ForeignKey(ExamResult, 
edit_inline=models.TABULAR, num_in_admin=1)
exam_attribute = 
models.ForeignKey(ExamAttribute,limit_choices_to={"exam__id":1})
 calification = models.IntegerField(core=True)


As you can see, in the last line I've a hardcoded "1". This id should be 
taken dynamically from exam_result.exam.id model attribute.

How could I accomplish this?

Thanks for your help.


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



override get_FOO_url()

2008-04-25 Thread Matias Surdi

is it possible to override get_FOO_url() for a FileField in a model?

if not:
  What is the recommended way to require login for users to download a file?


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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: weird error [corrected]

2008-04-25 Thread Matias Surdi

Karen Tracey escribió:
> On Fri, Apr 25, 2008 at 8:02 AM, Matias Surdi <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
> 
> Matias Surdi escribió:
>  > Sorry, there was an error in the previous message:
>  >
>  >
>  > With the following model:
>  >
>  > class Candidate(models.Model):
>  >  name = models.CharField(max_length=100,unique=True)
>  >  file =
>  > models.FileField(upload_to="curriculums/%Y/%m/%d",max_length=300)
>  >
>  >  def _get_FIELD_url(self,field):
>  >  return "http://www.google.es;
>  >  if getattr(self, field.attname): # value is not blank
>  >  import urlparse
>  >  return urlparse.urljoin(settings.MEDIA_URL,
> getattr(self,
>  > field.attname)).replace('\\', '/')
>  >  return ''
>  >
>  >
>  > when I do object.get_file_url(), http://www.google.es is returned, as
>  > expected
>  >
>  > but with the following one:
>  >
>  > class Candidate(models.Model):
>  >  name = models.CharField(max_length=100,unique=True)
>  >  curriculum =
>  > models.FileField(upload_to="curriculums/%Y/%m/%d",max_length=300)
>  >
>  >  def _get_FIELD_url(self,field):
>  >  return "http://www.google.es;
>  >  if getattr(self, field.attname): # value is not blank
>  >  import urlparse
>  >  return urlparse.urljoin(settings.MEDIA_URL,
> getattr(self,
>  > field.attname)).replace('\\', '/')
>  >  return ''
>  >
>  > when I do object.get_cirriculum_url(), I don't get the same
> result than
>  > with
>  > the first one.
>  >
> 
> 
> Well, what result do you get?  Why not tell us instead of making us guess?
> 
> Unless it's a typo. one problem is you have is you try to get the 
> 'cirriculum' url but you named the field 'curriculum'.
> 
> (I'm also wondering why you are overriding _get_FIELD_url at all, since 
> it seems pretty hackish, but I guess that's beside the point.)
>  
> 
> 
>  > The only difference is the field name.
>  >
>  > am I missing something here? what could be happening?
>  >
>  > NOTE: Database is destroyed/recreated on each test.
>  >
>  > Thanks.
>  >
>  >
>  > >
>  >
> 
> I think I'm isolating the problem, I think it's related to the field's
> name size... when it's longer than 8 character, the problem appears.
> 
> 
> That's surprising, since there's nothing in Django that has any 
> dependence on field name length here.
> 
> Karen
> 
> > 

Despite the typo, I'm still having the same problem.

What I want to do, is not to have a "public" download url I want to 
check user's permissions before a download is started. So, I want to 
change the behaviour of get__url so that it returns a custom view 
instead of the public url.





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



Re: weird error [corrected]

2008-04-25 Thread Matias Surdi

Matias Surdi escribió:
> Sorry, there was an error in the previous message:
> 
> 
> With the following model:
> 
> class Candidate(models.Model):
>  name = models.CharField(max_length=100,unique=True)
>  file =
> models.FileField(upload_to="curriculums/%Y/%m/%d",max_length=300)
> 
>  def _get_FIELD_url(self,field):
>  return "http://www.google.es;
>  if getattr(self, field.attname): # value is not blank
>  import urlparse
>  return urlparse.urljoin(settings.MEDIA_URL, getattr(self,
> field.attname)).replace('\\', '/')
>  return ''
> 
> 
> when I do object.get_file_url(), http://www.google.es is returned, as
> expected
> 
> but with the following one:
> 
> class Candidate(models.Model):
>  name = models.CharField(max_length=100,unique=True)
>  curriculum =
> models.FileField(upload_to="curriculums/%Y/%m/%d",max_length=300)
> 
>  def _get_FIELD_url(self,field):
>  return "http://www.google.es;
>  if getattr(self, field.attname): # value is not blank
>  import urlparse
>  return urlparse.urljoin(settings.MEDIA_URL, getattr(self,
> field.attname)).replace('\\', '/')
>  return ''
> 
> when I do object.get_cirriculum_url(), I don't get the same result than 
> with
> the first one.
> 
> The only difference is the field name.
> 
> am I missing something here? what could be happening?
> 
> NOTE: Database is destroyed/recreated on each test.
> 
> Thanks.
> 
> 
> > 
> 

I think I'm isolating the problem, I think it's related to the field's 
name size... when it's longer than 8 character, the problem appears.



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



weird error [corrected]

2008-04-25 Thread Matias Surdi

Sorry, there was an error in the previous message:


With the following model:

class Candidate(models.Model):
 name = models.CharField(max_length=100,unique=True)
 file =
models.FileField(upload_to="curriculums/%Y/%m/%d",max_length=300)

 def _get_FIELD_url(self,field):
 return "http://www.google.es;
 if getattr(self, field.attname): # value is not blank
 import urlparse
 return urlparse.urljoin(settings.MEDIA_URL, getattr(self,
field.attname)).replace('\\', '/')
 return ''


when I do object.get_file_url(), http://www.google.es is returned, as
expected

but with the following one:

class Candidate(models.Model):
 name = models.CharField(max_length=100,unique=True)
 curriculum =
models.FileField(upload_to="curriculums/%Y/%m/%d",max_length=300)

 def _get_FIELD_url(self,field):
 return "http://www.google.es;
 if getattr(self, field.attname): # value is not blank
 import urlparse
 return urlparse.urljoin(settings.MEDIA_URL, getattr(self,
field.attname)).replace('\\', '/')
 return ''

when I do object.get_cirriculum_url(), I don't get the same result than
with
the first one.

The only difference is the field name.

am I missing something here? what could be happening?

NOTE: Database is destroyed/recreated on each test.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



weird error [corrected]

2008-04-25 Thread Matias Surdi

Sorry, there was an error in the previous message:


With the following model:

class Candidate(models.Model):
 name = models.CharField(max_length=100,unique=True)
 file =
models.FileField(upload_to="curriculums/%Y/%m/%d",max_length=300)

 def _get_FIELD_url(self,field):
 return "http://www.google.es;
 if getattr(self, field.attname): # value is not blank
 import urlparse
 return urlparse.urljoin(settings.MEDIA_URL, getattr(self,
field.attname)).replace('\\', '/')
 return ''


when I do object.get_file_url(), http://www.google.es is returned, as
expected

but with the following one:

class Candidate(models.Model):
 name = models.CharField(max_length=100,unique=True)
 curriculum =
models.FileField(upload_to="curriculums/%Y/%m/%d",max_length=300)

 def _get_FIELD_url(self,field):
 return "http://www.google.es;
 if getattr(self, field.attname): # value is not blank
 import urlparse
 return urlparse.urljoin(settings.MEDIA_URL, getattr(self,
field.attname)).replace('\\', '/')
 return ''

when I do object.get_cirriculum_url(), I don't get the same result than 
with
the first one.

The only difference is the field name.

am I missing something here? what could be happening?

NOTE: Database is destroyed/recreated on each test.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



weird error

2008-04-25 Thread Matias Surdi

With the following model:

class Candidate(models.Model):
 name = models.CharField(max_length=100,unique=True)
 file = 
models.FileField(upload_to="curriculums/%Y/%m/%d",max_length=300)

 def _get_FIELD_url(self,field):
 return "http://www.google.es;
 if getattr(self, field.attname): # value is not blank
 import urlparse
 return urlparse.urljoin(settings.MEDIA_URL, getattr(self, 
field.attname)).replace('\\', '/')
 return ''


when I do object.get_file_url(), http://www.google.es is returned, as 
expected

but with the following one:

class Candidate(models.Model):
 name = models.CharField(max_length=100,unique=True)
 curriculum = 
models.FileField(upload_to="curriculums/%Y/%m/%d",max_length=300)

 def _get_FIELD_url(self,field):
 return "http://www.google.es;
 if getattr(self, field.attname): # value is not blank
 import urlparse
 return urlparse.urljoin(settings.MEDIA_URL, getattr(self, 
field.attname)).replace('\\', '/')
 return ''

when I do object.get_file_url(), I don't get the same result than with 
the first one.

The only difference is the field name.

am I missing something here? what could be happening?

NOTE: Database is destroyed/recreated on each test.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



order_by for related tables

2008-04-24 Thread Matias Surdi

Hi again,

I can't get to work the order_by('related_table.field') as described in 
http://www.djangoproject.com/documentation/db-api/#order-by-fields

Is this documentation correct?

I'm using django from SVN trunk.

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Zero padding an intger in templates

2008-04-24 Thread Matias Surdi

Matias Surdi escribió:
> Hi.
> 
> Which is the correct way to zero-pad an integer in templates? is there 
> any filter?
> 
> Thanks a lot.
> 
> 
> > 
> 

Found it:  variable|stringformat:"04i"


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



Zero padding an intger in templates

2008-04-24 Thread Matias Surdi

Hi.

Which is the correct way to zero-pad an integer in templates? is there 
any filter?

Thanks a lot.


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



Re: Exceptions by mail

2008-04-10 Thread Matias Surdi

Marc Fargas escribió:
> Simply set DEBUG=False in your settings.py, when an exception raises
> django will send the traceback to the people defined in ADMINS (also in
> settings.py)
> 
> Documentation about that is:
> http://www.djangoproject.com/documentation/settings/#error-reporting-via-e-mail
> 
> 
> Regards,
> Marc
> 
> El jue, 10-04-2008 a las 09:46 +0200, Matias Surdi escribió:
>> Hi,
>>
>> I've read somewhere that there is a way in django to send exceptions by 
>> mail. I can't remember where.
>>
>> Does anyone know where could I find documentation about that?
>>
>>
>> >>

Thanks a lot.That was :-)




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



Exceptions by mail

2008-04-10 Thread Matias Surdi

Hi,

I've read somewhere that there is a way in django to send exceptions by 
mail. I can't remember where.

Does anyone know where could I find documentation about that?


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



override get_file_url()

2008-04-08 Thread Matias Surdi

Hi.

I'm trying to upload files to a directory that is not under the web 
server root, for security reasons.

I wonder if is it possible to override the model's "get_FOO_url()" 
method so that It will return some form of encoded url.

I've already achieved this by defining in my model's class a 
_get_FIELD_url(self,field) method, but I'm not sure that is the correct 
way to do this.


Thanks a lot.


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



Re: newforms initial value

2008-04-05 Thread Matias Surdi

Matias Surdi escribió:
> Hi.
> 
> How can I pass an initial value to a newforms form's widget?
> 
> I know that there is an "initial" parameter for widgets, but what if I 
> don't know that parameter's value beforehand?
> 
> What I'm trying to do is to be able to make a request to an url and 
> depending on some url parameters generate a form wich will take its 
> initial values from those url parameters.
> 
> Any idea?
> 
> Thanks a lot.
> 
> 
> > 
> 

I think what I was looking for is this:

 >>> MyForm.base_fields["url"].initial="http://www.url.com;


Could this cause any problem? Is this the correct way to do this?

Thanks for your help.



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



newforms initial value

2008-04-05 Thread Matias Surdi

Hi.

How can I pass an initial value to a newforms form's widget?

I know that there is an "initial" parameter for widgets, but what if I 
don't know that parameter's value beforehand?

What I'm trying to do is to be able to make a request to an url and 
depending on some url parameters generate a form wich will take its 
initial values from those url parameters.

Any idea?

Thanks a lot.


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



Custom tag keword arguments

2008-04-04 Thread Matias Surdi

Hi,
Is it possible to pass keyword arguments to a custom inclusion tag?


example:


@register.inclusion_tag('shared/form.html')
def form(form, action="",method="POST"):
 return {"form": form,
 "action": action,
 "method": method}


I'd like to call this from a template, using something like this:

{{ form myform,method="POST"}}

What is the correct way to do this?


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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django newbie question about views and authentication

2008-04-01 Thread Matias Surdi

Hi,

Suppose I've the following on the top of every page of my application 
(in base.html for example):

{% if user.is_authenticated %}
 Welcome, {{ user.username }}. Thanks for logging in.
{% else %}
 Welcome, new user. Please log in.
{% endif %}


Now, as far as I understand I must ALWAYS do the following in ALL views:


def index(request):
 render_to_response('template/index.html',{},
 context_instance=RequestContext(request))

So, I have to pass always the parameter context_instance to the 
render_to_response shortcut.

¿Is this correct? Isn't it a bit tedious to do this with all views? What 
if I forget to add the RequestContext thing in a view?


Any aclaration will be appreciated.

Thanksa lot.


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



Re: Strange filtering issue

2007-03-15 Thread Matias Surdi

Malcolm Tredinnick escribió:

> 
> On Thu, 2007-03-15 at 21:53 +0100, Matias Surdi wrote:
>> Hi,
>> 
>> I'm my urls.py I have the following queryset for a generic view:
>> 
>> published_posts_dict = {'queryset':
>>
Post.objects.filter(pub_date__lte=datetime.now()).filter(status='PB').order_by('-pub_date')}
>> 
>> the problem is, with the filter pub_date__lte=datetime.now() .
> 
> The datetime.now() is evaluated exactly once -- when this dictionary is
> created. That is at import time. So, not surprisingly, as real world
> time moves forwards, the date you are comparing against remains in the
> past.
> 
> A couple of alternatives are:
> 
> (1) Wrap the generic view in another function to compute the real
> queryset (see
>
http://www.pointy-stick.com/blog/2006/06/29/django-tips-extending-generic-views/
> )
> 
> (2) Have a look in django/db/models/__init__.py at the LazyDate class.
> It is well documented in the docstrings, so it should be easy to work
> out how to use it. Replacing datetime.now() with LazyDate() should work,
> I suspect.
> 
> Regards,
> Malcolm
> 
> 
> 
> 


Thanks a lot!



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



Strange filtering issue

2007-03-15 Thread Matias Surdi

Hi,

I'm my urls.py I have the following queryset for a generic view:

published_posts_dict = {'queryset':
Post.objects.filter(pub_date__lte=datetime.now()).filter(status='PB').order_by('-pub_date')}

the problem is, with the filter pub_date__lte=datetime.now() .

What happens,is that when I add a new post to the database, it doesn't
appear listed until y restart the web server.

(it happens with the development server and with the prodction server, on
wich I have to touch the dispatch.fcgi file to view the new Post)

No problem exists if I remove that filter.

What could be happenning here?

Thanks a lot.



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