> What are you doing with the list once you generate it? Are you just running
> that single line of code, for instance, in a Python shell, or is this error
> generated in a view?

Attempt to "cast" QuerySet to list appeared during my experimentation
with Python/Django to see what I can do with both, and how practical
efficient both are for me. In this particular case, I am trying to
reproduce in Django one of the simplest techniques to implement
"Previous"/Next" type of navigation from records. So, in this case, I
open a Concept record. Instead of going back to a page with the list
of "concepts" I want to go directly to the next concept that would
appear next in such list.

> Can you post the rest of the code around this, or at least more of a
> traceback, unless that is really all that there is? And if it is, then I'd
> really like to take a look at your model definition.

Absolutely. I am glad you are willing to look at it - many thanks. See
below. Also, I would like to mention that there is no problem to find
workaround (in fact, on of them is in the code below (commented out)).
But I was just surprised that I could even do such seemingly simple
thing as list(QuerySet).

Best, regards,
Serge

===== in urls.py: ======
(r'^test/([-a-z0-9]+)/$', views.test),

===== in views.py: =======
see formatted http://dpaste.com/hold/552703/

same as:

def test(request, slug=None):
    slugs = Concept.objects.filter(status__slug = 'active').order_by('-
published_on').values_list('slug', flat=True)
    try:
        concept = Concept.objects.get(slug = slug, status__slug =
'active')
    except Page.DoesNotExist:
        raise Http404

    slugs_list = list(slugs)      # ======> problem line

#    object_slug = concept.slug
#    index = 1;
#    break_at_index = - 1;
#    previous_slug = None;
#    next_slug = None;
#
#    for slug in slugs:
#        if object_slug == slug:
#            break_at_index = index + 1
#        else:
#            if index == break_at_index:
#                next_slug = slug
#                break
#            else:
#                previous_slug = slug
#
#        index += 1

    concept_opportunities =
Opportunity.objects.filter(opportunity_concepts = concept.concept_id,
status__slug = 'active')
    concept_resources = concept.concept_resources.all()
    concept_types = concept.concept_types.all()
    concept_tags = concept.tags.all()
    context = {
        'header_title':'Concept',
        'object': concept,
        'concept_resources': concept_resources,
        'concept_types': concept_types,
        'concept_opportunities': concept_opportunities,
        'concept_tags': concept_tags,
        'previous_slug':previous_slug,
        'next_slug':next_slug,
        'page_marker':'co',
        'index': index - 1,
    }
    return render_to_response('page_concept.html',
                              context,
 
context_instance=RequestContext(request))

===== in models.py ========
class Concept(models.Model):

    concept_id = models.AutoField(primary_key=True)
    name = models.CharField(unique=True, max_length=100)
    slug = models.SlugField(max_length=45, blank=True, unique=True)
    meta_keywords = models.CharField(null=True, blank=True,
max_length=300 )
    meta_description = models.CharField(null=True, blank=True,
max_length=300 )
    status = models.ForeignKey(Status)
    enable_comments = models.BooleanField()
    description = models.CharField(null=True, blank=True,
max_length=1500, help_text='The body of concept item')
    published_on = models.DateField(null=True, blank=True)
    review_by = models.DateField(null=True, blank=True,
help_text='Date when the record should be reviewed to verify if the
concept still holds true.')
    date_created = models.DateField(auto_now_add=True, editable=False)
    date_updated = models.DateField(auto_now=True, editable=False)
    created_by = models.ForeignKey(User, null=True, blank=True,
related_name="concept_created_by", editable=False)
    updated_by = models.ForeignKey(User, null=True, blank=True,
related_name="concept_updated_by", editable=False)
    concept_resources = models.ManyToManyField(Resource)
    concept_types = models.ManyToManyField(Type)
    tags = TaggableManager(blank=True)

    class Meta:
        ordering = ['published_on']
        verbose_name = "Concept"
        verbose_name_plural = "Concepts"

    def __unicode__(self):
        return self.name

=====  traceback =========
http://dpaste.com/552702/

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

Reply via email to