Re: Howto not delete record after X days?

2009-07-28 Thread Dan Radez

How about pass in a context variable?

render the template with something like

conext = { ...snip
'editable':  form.entered <= date -3,
... snip ... }

then in your template do
{% if editable %}
  HTML Delete button
{% endif %}

On 07/28/2009 11:16 AM, Keith Pettit wrote:
> I need to be able to limit the ability to delete a record after it's
> been in the system for X days.  Any ideas on how to approach that?

> 
> {% if form.entered <= date -3 %}
>   HTML Delete button
> {% endif %}
> 



--~--~-~--~~~---~--~~
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: import a variable form views to forms

2009-06-29 Thread Dan Radez

On 06/29/2009 10:48 AM, ariest wrote:
> Sorry, this is the actual code:
>
> views.py
>
> def parent(request):
>  user = request.user
>  key = user.get_profile().link
>  p = Parent.objects.get(pk = key)
>  children = p.children.all()
>  if request.method == 'POST':
>  form = ComentForm(request.POST, children???)
>  if form.is_valid():
>  cd = form.cleaned_data
>  c = Coments(from=cd['from'], comentario=cd['coment'])
>  c.save()
>  return render_to_response('sent.html', locals())
>  else:
>  form = ComentForm(children???)
>  return render_to_response('parent.html', locals())
>
> forms.py
>
> class ComentForm(forms.Form):
>  def __init__(self, user_choices_list, *args, **kwargs):
>  super(ComentForm, self).__init__(*args, **kwargs)
>  self.fields['from'].choices = user_choices_list
>  from = forms.ChoiceField()
>  coment = forms.CharField(widget=forms.Textarea, label='Coment')
> >
>

I think you just have to call it like this:

form = ComentForm(request.POST, user_choices_list=children)


I've not done it passing the POST data too, only passing in a kwarg.

Hope this helps

Radez

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



Yet another schema managing idea

2009-06-25 Thread Dan Radez

I have been looking for a way to apply and manage my model changes to my 
db schema. This came out of a brainstorm yesterday afternoon. Just 
wanted to pass the idea through the community to see where it fits, if 
anywhere, upstream.

The general idea is to save sqlall output from manage.py. You then 
maintain sql files named after your apps and their versions.  Then just 
run the script against two of your files with the sqlall content in it. 
It takes the diff of two files and generates sql statements that will 
upgrade your schema from one version to another.

I went back and captured sqlall from a couple previous releases and used 
them to write the code. The proof-of-concept can modify columns, create 
and drop tables and add contraints and indexes. All in mysql at the 
moment. Haven't investigated supporting other databases yet.

I realize that other tools can do this too. I just wanted something 
small that only generated syntax. Is there anything I've missed that 
already does this and is more mature? Does anyone else like the idea of 
this style of schema management?

General example of use:
$ ./manage.py syncdb # initial install
$ ./manage.py sqlall appname > schemas/appname-1.1.0.sql
###  make modifications to model ###
$ ./manage.py sqlall appname > schemas/appname-1.2.0.sql
$ cd schemas
$ ./gen-db-update-script.py appname-1.1.0.sql appname-1.2.0.sql > 
update-appname-1.1.0to1.2.0.sql
$ cat update-appname-1.1.0to1.2.0.sql
CREATE TABLE `appname_tableone` (
 `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
 `group_id` integer NOT NULL,
 `content_type_id` integer NOT NULL,
 `object_id` integer UNSIGNED NOT NULL,
)
;
ALTER TABLE `appname_tabletwo` ADD COLUMN `prune_count` integer NOT NUL;
ALTER TABLE `appname_tabletwo` ADD COLUMN `prune_age` integer NOT NULL;
ALTER TABLE `appname_tabletwo` ADD COLUMN `prune_inactive` integer NOT NULL;
ALTER TABLE `appname_tablethree` MODIFY COLUMN `arch_id` integer NOT NULL;
$ mysql -u someuser -p databasename < update-appname-1.1.0to1.2.0.sql

Radez

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