Re: Problem with view

2021-02-25 Thread Umberto Moffa
Di niente!

Il giorno gio 25 feb 2021 alle 07:47 Maurizio Faccin <
maurizio.fac...@tiscali.it> ha scritto:

>
> Ciao,
> cambiando il nome delle classi funziona.
>
> Grazie mille!
>
>
> Maurizio
>
>
> Il 25/02/2021 01:14, Umberto Moffa ha scritto:
>
> Ciao, prova a cambiare il nome delle classi, forse chiamandosi Fatture sia
> il Model che la View va in pappa, oppure sovrascrivi il nome del Model
> quando lo importi nella view
>
> Esempio:
> “from model. import Fatture as *qualsiasi altro nome*
>
> Il giorno gio 25 feb 2021 alle 00:54 Maurizio Faccin <
> maurizio.fac...@tiscali.it> ha scritto:
>
>>
>> Hello,
>> I'am a newbie in usign django and django rest.
>> I have a problem with a modelsetview
>> The message error is:
>>
>> Exception Type: AttributeError
>> Exception Value:
>>
>> type object 'Fatture' has no attribute 'objects'
>>
>> Exception Location:
>> C:\Lavoro\Python\scambiosdi\scambiosdi\fatture\api\views.py, line 15, in
>> get_queryset
>>
>> This is the model.py:
>> from django.db import models
>> from scambiosdi import dataset
>> from utenti.models import Utenti
>>
>> class Fatture(models.Model):
>> utente = models.ForeignKey(Utenti, on_delete=models.CASCADE,
>> related_name="fatture")
>> tipo_fattura = models.IntegerField(choices=dataset.TIPOFATTURA)
>> denominazione = models.CharField(max_length=80)
>> numero = models.CharField(max_length=20)
>> data = models.DateField()
>> totale = models.DecimalField(max_digits=18, decimal_places=2,
>> default=0)
>> identificativo_sdi = models.CharField(max_length=50, blank=True)
>> percorso_file_originale = models.CharField(max_length=240, blank=True)
>> percorso_file_pulito = models.CharField(max_length=240, blank=True)
>>
>> class Meta():
>> verbose_name = 'Fattura'
>> verbose_name_plural = 'Fatture'
>>
>> def __str__(self):
>> return '{} {} {}'.format(self.denominazione, self.numero,
>> self.data)
>>
>>
>> This is the serializers.py:
>> from rest_framework import serializers
>> from fatture.models import Fatture
>>
>> class FatturaSerializer(serializers.ModelSerializer):
>> user = serializers.StringRelatedField(read_only=True)
>>
>> class Meta:
>> model = Fatture
>> fields = "__all__"
>>
>>
>>
>> And this is the views.py:
>> from rest_framework.viewsets import ModelViewSet
>> from rest_framework.permissions import IsAuthenticated
>> from fatture.models import Fatture
>> from fatture.api.serializers import FatturaSerializer
>>
>> class Fatture(ModelViewSet):
>> serializer_class = FatturaSerializer
>> permission_classes = [IsAuthenticated]
>>
>> def get_queryset(self):
>> queryset = Fatture.objects.all()
>> idfattura =  self.request.query_params.get("idfattura", None)
>> if idfattura is not None:
>> queryset = queryset.filter(id=idfattura)
>> return queryset
>>
>> If I change the Fatture class in this way works correctly:
>> class Fatture(ModelViewSet):
>> queryset = Fatture.objects.all()
>> serializer_class = FatturaSerializer
>> permission_classes = [IsAuthenticated]
>>
>>
>>
>>
>> Maurizio
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/d1883242-9b48-a158-1e27-cd021c60fd85%40tiscali.it
>> 
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFdc%3DxTYDDDb0yKme0Nsu-73ORhfpf9938%2B8nS3wFkZf6SxRcQ%40mail.gmail.com
> 
> .
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4acfb8fc-d9f1-e9f6-efa1-1a93a65e1a7e%40tiscali.it
> 
> .
>

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

Re: Problem with view

2021-02-24 Thread Maurizio Faccin


Ciao,
cambiando il nome delle classi funziona.

Grazie mille!


Maurizio

Il 25/02/2021 01:14, Umberto Moffa ha scritto:
Ciao, prova a cambiare il nome delle classi, forse chiamandosi Fatture 
sia il Model che la View va in pappa, oppure sovrascrivi il nome del 
Model quando lo importi nella view


Esempio:
“from model. import Fatture as *qualsiasi altro nome*

Il giorno gio 25 feb 2021 alle 00:54 Maurizio Faccin 
mailto:maurizio.fac...@tiscali.it>> ha 
scritto:



Hello,
I'am a newbie in usign django and django rest.
I have a problem with a modelsetview
The message error is:

Exception Type: AttributeError
Exception Value:

type object 'Fatture' has no attribute 'objects'

Exception Location:
C:\Lavoro\Python\scambiosdi\scambiosdi\fatture\api\views.py, line
15, in get_queryset

This is the model.py:
from django.db import models
from scambiosdi import dataset
from utenti.models import Utenti

class Fatture(models.Model):
    utente = models.ForeignKey(Utenti, on_delete=models.CASCADE,
related_name="fatture")
    tipo_fattura = models.IntegerField(choices=dataset.TIPOFATTURA)
    denominazione = models.CharField(max_length=80)
    numero = models.CharField(max_length=20)
    data = models.DateField()
    totale = models.DecimalField(max_digits=18, decimal_places=2,
default=0)
    identificativo_sdi = models.CharField(max_length=50, blank=True)
    percorso_file_originale = models.CharField(max_length=240,
blank=True)
    percorso_file_pulito = models.CharField(max_length=240,
blank=True)

    class Meta():
    verbose_name = 'Fattura'
    verbose_name_plural = 'Fatture'

    def __str__(self):
    return '{} {} {}'.format(self.denominazione, self.numero,
self.data)


This is the serializers.py:
from rest_framework import serializers
from fatture.models import Fatture

class FatturaSerializer(serializers.ModelSerializer):
    user = serializers.StringRelatedField(read_only=True)

    class Meta:
    model = Fatture
    fields = "__all__"



And this is the views.py:
from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAuthenticated
from fatture.models import Fatture
from fatture.api.serializers import FatturaSerializer

class Fatture(ModelViewSet):
    serializer_class = FatturaSerializer
    permission_classes = [IsAuthenticated]

    def get_queryset(self):
    queryset = Fatture.objects.all()
    idfattura = self.request.query_params.get("idfattura", None)
    if idfattura is not None:
    queryset = queryset.filter(id=idfattura)
    return queryset

If I change the Fatture class in this way works correctly:
class Fatture(ModelViewSet):
    queryset = Fatture.objects.all()
    serializer_class = FatturaSerializer
    permission_classes = [IsAuthenticated]




Maurizio

-- 
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 view this discussion on the web visit

https://groups.google.com/d/msgid/django-users/d1883242-9b48-a158-1e27-cd021c60fd85%40tiscali.it

.

--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFdc%3DxTYDDDb0yKme0Nsu-73ORhfpf9938%2B8nS3wFkZf6SxRcQ%40mail.gmail.com 
.



--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4acfb8fc-d9f1-e9f6-efa1-1a93a65e1a7e%40tiscali.it.


Re: Problem with view

2021-02-24 Thread Maurizio Faccin



I changed the classes name and works!
Thank you


Maurizio


Il 25/02/2021 01:09, Kasper Laudrup ha scritto:

On 24/02/2021 21.00, Maurizio Faccin wrote:


Hello,
I'am a newbie in usign django and django rest.
I have a problem with a modelsetview
The message error is:

Exception Type: AttributeError
Exception Value:

type object 'Fatture' has no attribute 'objects'



You have two classes called Fatture. In your models file and your 
views file. The Python interpreter needs to figure out which one of 
them to use.


When you call the objects method on the Fatture class it is using the 
class inheriting from models.Model but the tries to find the objects 
attribute as a static member in the same class where you're making the 
call.


You could either make it explicit which class to use by prefixing the 
call like *fattura.models.Fatture* but a better solution is probably 
to rename the classes to FattureModel and FattureView. That would also 
follow the naming patter from calling your serializer class 
FatturaSerializer.


Kind regards,

Kasper Laudrup



--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fd4fa7e8-90eb-f02d-6472-e3cf077c2409%40tiscali.it.


Re: Problem with view

2021-02-24 Thread Umberto Moffa
Ciao, prova a cambiare il nome delle classi, forse chiamandosi Fatture sia
il Model che la View va in pappa, oppure sovrascrivi il nome del Model
quando lo importi nella view

Esempio:
“from model. import Fatture as *qualsiasi altro nome*

Il giorno gio 25 feb 2021 alle 00:54 Maurizio Faccin <
maurizio.fac...@tiscali.it> ha scritto:

>
> Hello,
> I'am a newbie in usign django and django rest.
> I have a problem with a modelsetview
> The message error is:
>
> Exception Type: AttributeError
> Exception Value:
>
> type object 'Fatture' has no attribute 'objects'
>
> Exception Location:
> C:\Lavoro\Python\scambiosdi\scambiosdi\fatture\api\views.py, line 15, in
> get_queryset
>
> This is the model.py:
> from django.db import models
> from scambiosdi import dataset
> from utenti.models import Utenti
>
> class Fatture(models.Model):
> utente = models.ForeignKey(Utenti, on_delete=models.CASCADE,
> related_name="fatture")
> tipo_fattura = models.IntegerField(choices=dataset.TIPOFATTURA)
> denominazione = models.CharField(max_length=80)
> numero = models.CharField(max_length=20)
> data = models.DateField()
> totale = models.DecimalField(max_digits=18, decimal_places=2,
> default=0)
> identificativo_sdi = models.CharField(max_length=50, blank=True)
> percorso_file_originale = models.CharField(max_length=240, blank=True)
> percorso_file_pulito = models.CharField(max_length=240, blank=True)
>
> class Meta():
> verbose_name = 'Fattura'
> verbose_name_plural = 'Fatture'
>
> def __str__(self):
> return '{} {} {}'.format(self.denominazione, self.numero,
> self.data)
>
>
> This is the serializers.py:
> from rest_framework import serializers
> from fatture.models import Fatture
>
> class FatturaSerializer(serializers.ModelSerializer):
> user = serializers.StringRelatedField(read_only=True)
>
> class Meta:
> model = Fatture
> fields = "__all__"
>
>
>
> And this is the views.py:
> from rest_framework.viewsets import ModelViewSet
> from rest_framework.permissions import IsAuthenticated
> from fatture.models import Fatture
> from fatture.api.serializers import FatturaSerializer
>
> class Fatture(ModelViewSet):
> serializer_class = FatturaSerializer
> permission_classes = [IsAuthenticated]
>
> def get_queryset(self):
> queryset = Fatture.objects.all()
> idfattura =  self.request.query_params.get("idfattura", None)
> if idfattura is not None:
> queryset = queryset.filter(id=idfattura)
> return queryset
>
> If I change the Fatture class in this way works correctly:
> class Fatture(ModelViewSet):
> queryset = Fatture.objects.all()
> serializer_class = FatturaSerializer
> permission_classes = [IsAuthenticated]
>
>
>
>
> Maurizio
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d1883242-9b48-a158-1e27-cd021c60fd85%40tiscali.it
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFdc%3DxTYDDDb0yKme0Nsu-73ORhfpf9938%2B8nS3wFkZf6SxRcQ%40mail.gmail.com.


Re: Problem with view

2021-02-24 Thread Kasper Laudrup

On 24/02/2021 21.00, Maurizio Faccin wrote:


Hello,
I'am a newbie in usign django and django rest.
I have a problem with a modelsetview
The message error is:

Exception Type: AttributeError
Exception Value:

type object 'Fatture' has no attribute 'objects'



You have two classes called Fatture. In your models file and your views 
file. The Python interpreter needs to figure out which one of them to use.


When you call the objects method on the Fatture class it is using the 
class inheriting from models.Model but the tries to find the objects 
attribute as a static member in the same class where you're making the call.


You could either make it explicit which class to use by prefixing the 
call like *fattura.models.Fatture* but a better solution is probably to 
rename the classes to FattureModel and FattureView. That would also 
follow the naming patter from calling your serializer class 
FatturaSerializer.


Kind regards,

Kasper Laudrup

--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/698f2316-465e-9218-3b1b-2b59a48bb6a1%40stacktrace.dk.


Problem with view

2021-02-24 Thread Maurizio Faccin


Hello,
I'am a newbie in usign django and django rest.
I have a problem with a modelsetview
The message error is:

Exception Type: AttributeError
Exception Value:

type object 'Fatture' has no attribute 'objects'

Exception Location: 
C:\Lavoro\Python\scambiosdi\scambiosdi\fatture\api\views.py, line 15, in 
get_queryset


This is the model.py:
from django.db import models
from scambiosdi import dataset
from utenti.models import Utenti

class Fatture(models.Model):
    utente = models.ForeignKey(Utenti, on_delete=models.CASCADE, 
related_name="fatture")

    tipo_fattura = models.IntegerField(choices=dataset.TIPOFATTURA)
    denominazione = models.CharField(max_length=80)
    numero = models.CharField(max_length=20)
    data = models.DateField()
    totale = models.DecimalField(max_digits=18, decimal_places=2, 
default=0)

    identificativo_sdi = models.CharField(max_length=50, blank=True)
    percorso_file_originale = models.CharField(max_length=240, blank=True)
    percorso_file_pulito = models.CharField(max_length=240, blank=True)

    class Meta():
    verbose_name = 'Fattura'
    verbose_name_plural = 'Fatture'

    def __str__(self):
    return '{} {} {}'.format(self.denominazione, self.numero, 
self.data)



This is the serializers.py:
from rest_framework import serializers
from fatture.models import Fatture

class FatturaSerializer(serializers.ModelSerializer):
    user = serializers.StringRelatedField(read_only=True)

    class Meta:
    model = Fatture
    fields = "__all__"



And this is the views.py:
from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAuthenticated
from fatture.models import Fatture
from fatture.api.serializers import FatturaSerializer

class Fatture(ModelViewSet):
    serializer_class = FatturaSerializer
    permission_classes = [IsAuthenticated]

    def get_queryset(self):
    queryset = Fatture.objects.all()
    idfattura =  self.request.query_params.get("idfattura", None)
    if idfattura is not None:
    queryset = queryset.filter(id=idfattura)
    return queryset

If I change the Fatture class in this way works correctly:
class Fatture(ModelViewSet):
    queryset = Fatture.objects.all()
    serializer_class = FatturaSerializer
    permission_classes = [IsAuthenticated]


Maurizio

--
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d1883242-9b48-a158-1e27-cd021c60fd85%40tiscali.it.


Re: [View Django] Problem with view that makes add and update

2013-08-30 Thread Marcos Luiz Wilhelm
Hello!
The problem that occurred was that the view when answering the case of 
modification, the id of the record was not passed when submitting the form. 
My solution was to add a block if / else to change the action of the form.
The following code: http://pastebin.com/BtPrpqSJ

I do not know if it is the best practice, but I think a simple solution.
Thanks C. Kirby.
Hug!

Em segunda-feira, 26 de agosto de 2013 12h40min52s UTC-3, Marcos Luiz 
Wilhelm escreveu:
>
> Hello!
> I'm having problems with a view that makes add and update
> The view generates a new record rather than change a instance.
> My code is this: http://pastebin.com/rZNAeN0p
> Someone can help me please?
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [View Django] Problem with view that makes add and update

2013-08-26 Thread C. Kirby
Have you verified that the url being called has a music_id?

On Monday, August 26, 2013 10:40:52 AM UTC-5, Marcos Luiz Wilhelm wrote:
>
> Hello!
> I'm having problems with a view that makes add and update
> The view generates a new record rather than change a instance.
> My code is this: http://pastebin.com/rZNAeN0p
> Someone can help me please?
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


[View Django] Problem with view that makes add and update

2013-08-26 Thread Marcos Luiz Wilhelm
Hello!
I'm having problems with a view that makes add and update
The view generates a new record rather than change a instance.
My code is this: http://pastebin.com/rZNAeN0p
Someone can help me please?

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.


Re: weird request.user problem in view

2010-02-13 Thread Anders Eide
I know. Just a typo in this post. Thanks for trying to help anyway :)

the error was in the urls.py


/user//
/user/page/

When loading /user/page/ /user/ wrote:
> On 13 February 2010 13:46, Anders Eide  wrote:
>
>
>
> > did a stupid PEBCAK i the urls.py file. Works fine now
>
> > On Feb 13, 1:33 pm, Anders Eide  wrote:
> >> Why on earth doesn't this user_page view work? Getting "404, No User
> >> matches the given query."
>
> >> from django.contrib.auth.models import User
> >> from django.template import RequestContext
> >> from django.shortcuts import render_to_response, get_object_or_404
>
> >> def user_page(request):
> >>     user = get_object_or_404(User,
> >> username=request.user.username)
> >>     movies = user.mymovie_set.all()
> >>     variables = RequestContext(request, {
> >>         'movies': movies,
> >>     })
> >>     return render_to_response('user_page/user_page.home.view.html',
> >> variables)
>
> >> The user is loged 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-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> user = User.get_object_or_404(User, username=request.user.username)
>
> I don't think you need this, request.user is already an instance of User.
> Try:
>
> movies = request.user.mymovie_set.all()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: weird request.user problem in view

2010-02-13 Thread rebus_
On 13 February 2010 13:46, Anders Eide  wrote:
> did a stupid PEBCAK i the urls.py file. Works fine now
>
> On Feb 13, 1:33 pm, Anders Eide  wrote:
>> Why on earth doesn't this user_page view work? Getting "404, No User
>> matches the given query."
>>
>> from django.contrib.auth.models import User
>> from django.template import RequestContext
>> from django.shortcuts import render_to_response, get_object_or_404
>>
>> def user_page(request):
>>     user = get_object_or_404(User,
>> username=request.user.username)
>>     movies = user.mymovie_set.all()
>>     variables = RequestContext(request, {
>>         'movies': movies,
>>     })
>>     return render_to_response('user_page/user_page.home.view.html',
>> variables)
>>
>> The user is loged 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-us...@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.
>
>

user = User.get_object_or_404(User, username=request.user.username)

I don't think you need this, request.user is already an instance of User.
Try:

movies = request.user.mymovie_set.all()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: weird request.user problem in view

2010-02-13 Thread Anders Eide
did a stupid PEBCAK i the urls.py file. Works fine now

On Feb 13, 1:33 pm, Anders Eide  wrote:
> Why on earth doesn't this user_page view work? Getting "404, No User
> matches the given query."
>
> from django.contrib.auth.models import User
> from django.template import RequestContext
> from django.shortcuts import render_to_response, get_object_or_404
>
> def user_page(request):
>     user = get_object_or_404(User,
> username=request.user.username)
>     movies = user.mymovie_set.all()
>     variables = RequestContext(request, {
>         'movies': movies,
>     })
>     return render_to_response('user_page/user_page.home.view.html',
> variables)
>
> The user is loged 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-us...@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.



weird request.user problem in view

2010-02-13 Thread Anders Eide
Why on earth doesn't this user_page view work? Getting "404, No User
matches the given query."

from django.contrib.auth.models import User
from django.template import RequestContext
from django.shortcuts import render_to_response, get_object_or_404

def user_page(request):
user = User.get_object_or_404(User,
username=request.user.username)
movies = user.mymovie_set.all()
variables = RequestContext(request, {
'movies': movies,
})
return render_to_response('user_page/user_page.home.view.html',
variables)


The user is loged 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-us...@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: Newbie problem with view/model interaction

2007-03-26 Thread [EMAIL PROTECTED]

Sorry I didn't see this thead earlier.

We wrote a proposal review system for PyCon2007. The source code is
under the Python License.
http://us.pycon.org/TX2007/PyConTech
https://svn.python.org/conference/django/trunk/

The goal is to write conference software for any conference.
I could use some help on this.

Applications:
PHP integration (wiki/site is PHP)
User Account signup with e-mail confirmation.
User Model extensions
Proposal review system.(http://us.pycon.org/apps07/proposals/)
Accepted talk listing (http://us.pycon.org/apps07/talks/)
Schedule system (http://us.pycon.org/apps07/schedule)
Custom ReStructuredText Markup with form validation

There are ShowMeDo's covering a fare amount of the the features:
http://showmedo.com/videos/video?name=pythonNapleonePyConTech1=54
Unfortunately I have yet to make on on the proposal system.
I am on the hook for getting the video encoded for the conference, and
that will be taking up allot of my time.

Features of proposal system:
The system uses ReST for the submission markup, with e-mail
notification.
Views can be turned on and off based on date from the Admin
(submissions close on date X, reviews start after date Y, etc.)
File upload/attachment to proposals.
Search interface.
3 Reviewers are randomly assigned on a new submission (and recieve e-
mails).
Reviewers can add comments and authors can respond in threads in the
proposal.
Reviewers can make reviews (-1, -0, +0, +1)
Presenters do not see the names of reviewers, reviewers do not see the
names of presenters (Configurable via permissions in the admin)
Actually there are MANY custom permissions:
permissions = (("can_view_all_proposals","Can view all
proposals"),
   ("can_view_proposal_listing", "Can view summary
listing"),
   ("can_view_proposal_stats",   "Can view
stats"),
   ("can_view_all_authors_override",
"Can view all proposal authors
(absolute)"),)
permissions = (("can_view_all_reviews","Can view all
reviews"),)
permissions = (("can_view_all_comments","Can view all
comments"),)
Many More...
There is a history system so when people log in updated proposals are
in Bold.
There are extensive reviewer stats pages, and Organizer overview
pages.

Pictures are worth 1000 words:
http://us.pycon.org/common/prop1.jpg
http://us.pycon.org/common/prop2.jpg
http://us.pycon.org/common/prop3.jpg
http://us.pycon.org/common/prop4.jpg

I was limited in what I could show as I didn't want to give out
sensitive info.
Let me know if you are interested in this, and/or would like to work
on it.

-Doug ([EMAIL PROTECTED])

On Mar 24, 10:55 am, "Ross Burton" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> (I'm a bit of a newbie to Django so excuse any foolish mistakes)
>
> I'm writing a basic paper review system for a conference (Paper is the
> primary object, with Note and Vote objects having a foreign key to the
> paper), and currently have it somewhat working.  Now my task is to
> make the list of papers (currently a generic object_list view) show
> whether the current user (all users are forced to login) has voted on
> each paper.
>
> My initial implementation was split across the template and the
> model.  In my model:
>
> class Paper (models.Model):
> ...
> def has_voted(paper, user):
> return paper.vote_set.filter(user__exact = user).count() != 0
>
> then in the view:
>
> {% for paper in object_list|dictsort:"title" %}
>   {% if paper.has_voted( TODO ) %}
> 
>
> I then discovered that you can't pass arguments to methods in
> templates, so I can't ask the model if the current user has voted.
>
> Can anyone give any hints on how I can fix this?
>
> Thanks,
> Ross


--~--~-~--~~~---~--~~
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: Newbie problem with view/model interaction

2007-03-26 Thread Malcolm Tredinnick

Hey Ross. :-)

On Mon, 2007-03-26 at 01:48 -0700, Ross Burton wrote:
> On Mar 25, 3:28 pm, "Ross Burton" <[EMAIL PROTECTED]> wrote:
> > > What is it you want to do with the ones they've voted on vs. haven't? If
> > > you're going to hide the ones they've already voted on, just write a
> > > query in the view method that only returns those and pass that to the
> > > context. (Note: the view method, not the template. See Ivan's response.)
> >
> > I thought I'd go this route -- it seemed simplier and more useful.
> > However, I can't seem to work out the query.  My initial attempt:
> >
> > def pending(request):
> > return object_list(request,
> > Paper.objects.exclude(vote__user=request.user))
> >
> > However this appears to joining Paper and Vote, filtering out the rows
> > where I voted, and then showing the rows remaining (which leads to
> > duplicates).
> >
> > What would the correct filter be for all Papers which don't have a
> > related Vote object with a given user field?
> 
> Ok so I'm a fool.  I now have this which works:
> 
> def pending(request):
> all_papers = Paper.objects.all()
> tuple_list = [p for p in all_papers if not
> p.has_voted(request.user)]
> return render_to_response('papers/paper_list.html',
> { 'object_list': tuple_list })
> 
> Would there be any theoretical advantage in using a generator to
> filter the list of all papers as it is iterated?

Not really worth worrying about, unless you have tens of thousands of
papers to review, which would suggest you more human-level problems.
Such as convincing your reviewers to read all of those submissions. :-)

The sort of problem discussed in this thread is an interesting one (it
comes up every now and again). There isn't really an easy to way to say
"object X isn't in the multi-element set at the other end of this
relation" with the Django query layer at the moment. At the SQL level,
it would involve something like "NOT EXISTS(...)" or a sub-select so
that you can filter on the count -- much as you are doing in the
has_voted() method. Implementing the mechanics of this query is about to
get easier, but we still need to think of a good way of expressing the
query.

I only mention this for the people who are going to wonder if you can do
the work in a single database query (the current method does p+1
queries, where p is the number of papers). You don't seem to be too
concerned about that, Ross, which is probably the right approach for a
practical problem like this (I'm guessing it's only going to be a few
papers for some reasonable definition of "few").

Regards,
Malcolm


--~--~-~--~~~---~--~~
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: Newbie problem with view/model interaction

2007-03-26 Thread Ross Burton

On Mar 25, 3:28 pm, "Ross Burton" <[EMAIL PROTECTED]> wrote:
> > What is it you want to do with the ones they've voted on vs. haven't? If
> > you're going to hide the ones they've already voted on, just write a
> > query in the view method that only returns those and pass that to the
> > context. (Note: the view method, not the template. See Ivan's response.)
>
> I thought I'd go this route -- it seemed simplier and more useful.
> However, I can't seem to work out the query.  My initial attempt:
>
> def pending(request):
> return object_list(request,
> Paper.objects.exclude(vote__user=request.user))
>
> However this appears to joining Paper and Vote, filtering out the rows
> where I voted, and then showing the rows remaining (which leads to
> duplicates).
>
> What would the correct filter be for all Papers which don't have a
> related Vote object with a given user field?

Ok so I'm a fool.  I now have this which works:

def pending(request):
all_papers = Paper.objects.all()
tuple_list = [p for p in all_papers if not
p.has_voted(request.user)]
return render_to_response('papers/paper_list.html',
{ 'object_list': tuple_list })

Would there be any theoretical advantage in using a generator to
filter the list of all papers as it is iterated?

Thanks,
Ross


--~--~-~--~~~---~--~~
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: Newbie problem with view/model interaction

2007-03-25 Thread Ross Burton

(re-sending, apologies if this hits the list twice)

On Mar 24, 5:27 pm, "Todd O'Bryan" <[EMAIL PROTECTED]> wrote:
> What is it you want to do with the ones they've voted on vs. haven't? If
> you're going to hide the ones they've already voted on, just write a
> query in the view method that only returns those and pass that to the
> context. (Note: the view method, not the template. See Ivan's response.)

I thought I'd go this route -- it seemed simplier and more useful.
However, I can't seem to work out the query.  My initial attempt:

def pending(request):
return object_list(request,
Paper.objects.exclude(vote__user=request.user))

However this appears to joining Paper and Vote, filtering out the rows
where I voted, and then showing the rows remaining (which leads to
duplicates).

What would the correct filter be for all Papers which don't have a
related Vote object with a given user field?

Thanks,
Ross


--~--~-~--~~~---~--~~
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: Newbie problem with view/model interaction

2007-03-24 Thread James Bennett

On 3/24/07, Ivan Sagalaev <[EMAIL PROTECTED]> wrote:
> Not related to your question, but this is called 'template' in Django.
> 'View' means a different thing (a controller).

Well, Django doesn't really have anything that strictly matches the
"controller" aspect; even Martin Fowler in his writeup of the MVC
pattern admits that controller/view separation isn't always useful :)

> I'm sure someone will suggest something less scary for a beginner but I
> can now only come up with such a custom template tag:

This is pretty much what I'd do (and what I've done in several
situations); given that this is a common situation it might be useful
for us to bundle an easy way to build if-style tags, much like the
simple_tag and inclusion_tag decorators.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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: Newbie problem with view/model interaction

2007-03-24 Thread Todd O'Bryan

What is it you want to do with the ones they've voted on vs. haven't? If
you're going to hide the ones they've already voted on, just write a
query in the view method that only returns those and pass that to the
context. (Note: the view method, not the template. See Ivan's response.)

If they have to be in alphabetical order by title and you're going to
show all of them, add something to each one that indicates whether
they've been voted on. Your list could morph into a list of tuples where
the first item is a paper and the second item is a boolean indicating
whether the current user has voted.

Something like:

def display_votes(request):
all_papers = Paper.objects.all()
tuple_list = [(p, p.has_voted(request.user)) for p in all_papers]
...

Then in the template:

{% for paper_voted in tuple_list %}
{% if paper_voted.1 %}
   stuff if they voted, paper is accessible as paper_voted.0
{% else %}
   stuff if they haven't
{% endif %}

HTH,
Todd

On Sat, 2007-03-24 at 07:55 -0700, Ross Burton wrote:

> My initial implementation was split across the template and the
> model.  In my model:
> 
> class Paper (models.Model):
> ...
> def has_voted(paper, user):
> return paper.vote_set.filter(user__exact = user).count() != 0
> 
> then in the view:
> 
> {% for paper in object_list|dictsort:"title" %}
>   {% if paper.has_voted( TODO ) %}
> 
> 
> I then discovered that you can't pass arguments to methods in
> templates, so I can't ask the model if the current user has voted.
> 
> Can anyone give any hints on how I can fix this?
> 
> Thanks,
> Ross



--~--~-~--~~~---~--~~
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: Newbie problem with view/model interaction

2007-03-24 Thread Ivan Sagalaev

Ross Burton wrote:
> then in the view:
> 
> {% for paper in object_list|dictsort:"title" %}
>   {% if paper.has_voted( TODO ) %}
> 

Not related to your question, but this is called 'template' in Django. 
'View' means a different thing (a controller).

> I then discovered that you can't pass arguments to methods in
> templates, so I can't ask the model if the current user has voted.

I'm sure someone will suggest something less scary for a beginner but I 
can now only come up with such a custom template tag:

 class IfVotedNode(template.Node):
   def __init__(self, paper_expr, node_list):
 self.paper_expr, self.node_list = obj_expr, node_list

   def render(self, context):
 paper = self.paper_expr.resolve(context)
 if paper.has_voted(context['user']):
   return self.node_list.render(context)
 else:
   return ''

 @register.tag
 def ifvoted(parser, token):
   bits = token.contents.split()
   if len(bits) != 2:
 raise template.TemplateSyntaxError, '"%s" takes 1 parameter ' % 
bits[0]
   node_list = parser.parse('end' + bits[0])
   parser.delete_first_token()
   return IfVotedNode(parser.compile_filter(bits[1]),node_list)

It's then used like this:

 {% ifvoted paper %}...{% endifvoted %}

Docs on creating custom template tags are here: 
http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-tags

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



Newbie problem with view/model interaction

2007-03-24 Thread Ross Burton

Hi,

(I'm a bit of a newbie to Django so excuse any foolish mistakes)

I'm writing a basic paper review system for a conference (Paper is the
primary object, with Note and Vote objects having a foreign key to the
paper), and currently have it somewhat working.  Now my task is to
make the list of papers (currently a generic object_list view) show
whether the current user (all users are forced to login) has voted on
each paper.

My initial implementation was split across the template and the
model.  In my model:

class Paper (models.Model):
...
def has_voted(paper, user):
return paper.vote_set.filter(user__exact = user).count() != 0

then in the view:

{% for paper in object_list|dictsort:"title" %}
  {% if paper.has_voted( TODO ) %}


I then discovered that you can't pass arguments to methods in
templates, so I can't ask the model if the current user has voted.

Can anyone give any hints on how I can fix this?

Thanks,
Ross


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