How to timestamp with MySQL?

2009-01-15 Thread Marc Barranco

Hi there,

I created a model with a date field in order to have a timestamp of
when has been the last modification of the object.

As in the basic tutorial I wrote my model as:
 data = models.DateTimeField ()

Wich should be in SQL:
 "data" timestamp with time zone NOT NULL

(ref: http://docs.djangoproject.com/en/dev/intro/tutorial01/)

However I get this SQL:

CREATE TABLE `projectes_projecte` (
   ()
`data` datetime NOT NULL,
   (...)

where the field data does never auto update.

I've seen (googling) that in MySQL the synatx is different than
"timestamp" but does anyone knows how could I fix it by writing the
django model?

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



Re: Problems with file upload and model forms

2008-11-21 Thread Marc Barranco

Oh yeah!! It was that! Thank you veru much Alex :)

I forgot to put the template code, Here it is (mayb useful for some
other):

--upload.html--








{% for field in form %}

{{ field.label_tag }}
{{ field }}
{% if field.help_text %}{{ field.help_text }}{% 
endif %}
{% if field.errors %}{{ 
field.errors }}
{% endif %}


{% endfor %}






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



Problems with file upload and model forms

2008-11-20 Thread Marc Barranco

Hi!
I'm trying to upload a file like the example in documentation in
Django (http://docs.djangoproject.com/en/dev/topics/http/file-
uploads/)
with the "Forms from Models".
But I can't upload the file because the form always return the error
"this field is required" although selecting a file before submitting
the form.
The fact is that I can do it with the django admin site, but with the
the my own form I don't find where's the problem.

Here is the code:

---models.py-
from django import forms
from django.forms import ModelForm
from django.db import models

class UploadFile(models.Model):
title   = models.CharField(max_length=50)
file= models.FileField(upload_to="pdf/")

class UploadFileForm(forms.Form):
title = forms.CharField(max_length=50)
file  = forms.FileField()


views.py---
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from llunes.files.models import *

def upload(request):
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_file(request.FILES['file']) # <--In 
fact it never
entries here

#'cause it seems that the

#form is not valid
return HttpResponseRedirect('/files/upload/')
else:
form = UploadFileForm()
return render_to_response('files/upload.html', {'form': form})

def handle_uploaded_file(f):
destination = open('tmp.pdf', 'wb+')
for chunk in f.chunks():
destination.write(chunk)
destination.close()


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