Re: Model opinnions

2015-07-26 Thread durirompepc
Yeah, there is a test image to do the work. But I'm not using HTML elements 
to see it: I'm trying to directly see it with the URL, like when you open a 
Twitter image in a new tab.

About the setup...
MEDIA_ROOT = os.path.join(BASE_DIR, '/media/')
MEDIA_URL = '/media/'
So *localhost:8000/media/images/avatar.jpg* would work, isn't it?


El sábado, 25 de julio de 2015, 23:14:58 (UTC+2), Gergely Polonkai escribió:
>
> Do you save your avatar images there? Do you prepend MEDIA_URL to the 
> avatar's src=""? How do you display the image by the way?
>
> These are the quick questions that came into my mind without knowing your 
> setup…
> On 25 Jul 2015 22:59, > wrote:
>
>> Nah, I just want to have an avatar inside, to get easy.
>>
>> And I tried the media docs a few hours ago, but for some reason it 
>> doesn't work. I've to set specific URL in *urls.py* of the app? (Also 
>> notice that I use another folder inside media, but I don't think that's the 
>> problem).
>>
>> El viernes, 24 de julio de 2015, 13:47:26 (UTC+2), durir...@gmail.com 
>> escribió:
>>>
>>> I'm doing a little app that consists of a web page were users submits 
>>> their jokes (
>>> https://github.com/RompePC/django-muro_humoristas/tree/feature). I had 
>>> finished the models (a little overview would help), but I have one question.
>>>
>>> I want to use an avatar field for the users: however, I don't understand 
>>> well for what is *MEDIA_URL* (also, I would want to know where you 
>>> would put your *MEDIA_ROOT*, in a folder of the app, or in a directory 
>>> as one that gives the example 
>>> https://docs.djangoproject.com/en/1.8/ref/settings/#std:setting-MEDIA_ROOT
>>> ).
>>>
>>> Thanks (and sorry if anyone doesn't understand spanish hehe).
>>>
>>  -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/d1078810-e3b2-46e6-b6ca-15992d1f6ada%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4b1e02b3-abc7-4ea9-a6f6-05b88574022d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Thumbnails In Django

2015-07-26 Thread Tao Huang
I also came across some problems with sorl-thumbnail. It cannot generate 
"cache" folder and thumbnail_kvstore is always empty. Please see more 
detail in this question 

 
.

On Wednesday, July 22, 2015 at 3:37:11 AM UTC+8, Sadaf Noor wrote:
>
> In one of my projects I used sorl (
> https://github.com/mariocesar/sorl-thumbnail) instead, it was super easy 
> and best fit for my project. Every time it asks for a new thumbnail BUT 
> if it exists in its cache, then that one is returned. If it doesn't, a 
> new one is generated and stored, then returned. So ultimately it saves. I 
> don't know your use case. I am just saying it can be an option. 
>
> 2015-07-22 1:22 GMT+06:00 divyanshi kathuria  >:
>
>> I am using Django Rest framework. I have three fields in my Pin Model : 
>> image,thumbnail_medium and thumbnail_small. I want to create two thumbnails 
>> from the image. How to do that? I tried the following code : But it's not 
>> working.
>> from django.db import models
>> from django.contrib.auth.models import User
>> from thumbs import ImageWithThumbsField
>> #from taggit.managers import TaggableManager
>> from PIL import Image
>> from cStringIO import StringIO
>> from django.core.files.uploadedfile import SimpleUploadedFile
>> import os
>>
>>
>> class Pin(models.Model):
>> 
>> url = models.SlugField(blank=True, null=True)
>> title = models.TextField(blank=False,null=False,default='Untitled')
>> description = models.TextField(blank=True, null=True)
>> is_pro = models.BooleanField(default=False)
>> is_hidden = models.BooleanField(default=False)
>> is_for_sale = models.BooleanField(default=False)
>> is_pro = models.BooleanField(default=False)
>> price = models.DecimalField(blank=True, null=True, max_digits=10, 
>> decimal_places=2 ,default=0)
>> price_in_rs = models.BooleanField(default=False)
>> size_in_inches = models.BooleanField(default=True)
>> medium = models.TextField(blank=True, null=True)
>> length = models.DecimalField(blank=True, null=True, max_digits=10, 
>> decimal_places=2 ,default=0)
>> width = models.DecimalField(blank=True, null=True, max_digits=10, 
>> decimal_places=2 ,default=0)
>> hearts = models.IntegerField(blank=True, null=True, default=0)
>> image = models.ImageField(upload_to='pins/pin/originals/')
>> thumbnail = models.ImageField(upload_to='pins/pin/thumbnails/')
>> published = models.DateTimeField(auto_now_add=True)
>> #tags = TaggableManager()
>>
>> def __unicode__(self):
>> return self.url
>>
>> def save(self):
>> from PIL import Image
>> from cStringIO import StringIO
>> from django.core.files.uploadedfile import SimpleUploadedFile
>>
>> # Set our max thumbnail size in a tuple (max width, max height)
>> THUMBNAIL_SIZE = (50, 50)
>>
>> # Open original photo which we want to thumbnail using PIL's Image
>> # object
>> image = Image.open(self.image.name)
>>
>> # Convert to RGB if necessary
>> # Thanks to Limodou on DjangoSnippets.org
>> # http://www.djangosnippets.org/snippets/20/
>> if image.mode not in ('L', 'RGB'):
>> image = image.convert('RGB')
>>
>> # We use our PIL Image object to create the thumbnail, which 
>> already
>> # has a thumbnail() convenience method that contrains proportions.
>> # Additionally, we use Image.ANTIALIAS to make the image look 
>> better.
>> # Without antialiasing the image pattern artifacts may result.
>> image.thumbnail(THUMBNAIL_SIZE, Image.ANTIALIAS)
>>
>> # Save the thumbnail
>> temp_handle = StringIO()
>> image.save(temp_handle, 'png')
>> temp_handle.seek(0)
>>
>> # Save to the thumbnail field
>> suf = SimpleUploadedFile(os.path.split(self.image.name)[-1],
>> temp_handle.read(), content_type='image/png')
>> self.thumbnail.save(suf.name+'.png', suf, save=False)
>>
>> # Save this photo instance
>> super(Pin, self).save() 
>>
>> Can anyone figure out the problem here? Why is it not creating thumbnails?
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/13e46569-3641-438d-9201-fa079f7f89b2%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

Re: Model opinnions

2015-07-26 Thread Gergely Polonkai
It should, yes. But instead hardcoding /media in your templates, use {{
MEDIA_URL }}
On 26 Jul 2015 11:57,  wrote:

> Yeah, there is a test image to do the work. But I'm not using HTML
> elements to see it: I'm trying to directly see it with the URL, like when
> you open a Twitter image in a new tab.
>
> About the setup...
> MEDIA_ROOT = os.path.join(BASE_DIR, '/media/')
> MEDIA_URL = '/media/'
> So *localhost:8000/media/images/avatar.jpg* would work, isn't it?
>
>
> El sábado, 25 de julio de 2015, 23:14:58 (UTC+2), Gergely Polonkai
> escribió:
>>
>> Do you save your avatar images there? Do you prepend MEDIA_URL to the
>> avatar's src=""? How do you display the image by the way?
>>
>> These are the quick questions that came into my mind without knowing your
>> setup…
>> On 25 Jul 2015 22:59,  wrote:
>>
>>> Nah, I just want to have an avatar inside, to get easy.
>>>
>>> And I tried the media docs a few hours ago, but for some reason it
>>> doesn't work. I've to set specific URL in *urls.py* of the app? (Also
>>> notice that I use another folder inside media, but I don't think that's the
>>> problem).
>>>
>>> El viernes, 24 de julio de 2015, 13:47:26 (UTC+2), durir...@gmail.com
>>> escribió:

 I'm doing a little app that consists of a web page were users submits
 their jokes (
 https://github.com/RompePC/django-muro_humoristas/tree/feature). I had
 finished the models (a little overview would help), but I have one 
 question.

 I want to use an avatar field for the users: however, I don't
 understand well for what is *MEDIA_URL* (also, I would want to know
 where you would put your *MEDIA_ROOT*, in a folder of the app, or in a
 directory as one that gives the example
 https://docs.djangoproject.com/en/1.8/ref/settings/#std:setting-MEDIA_ROOT
 ).

 Thanks (and sorry if anyone doesn't understand spanish hehe).

>>>  --
>>> 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...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/d1078810-e3b2-46e6-b6ca-15992d1f6ada%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBUL17Vudf_pFn4s7UKct7g9%2BvfCn3H4GfwhON5p9RrDeLg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: "RuntimeError: Error creating new content types."

2015-07-26 Thread Tobias McNulty
I just ran into this issue as well when updating an old project to Django 
1.8. The only suitable workaround I found was to update first to Django 1.7 
and fake the initial migrations for my apps (presumably Django's as well, 
though it seems to handle that automatically). Only then can you safely 
update to Django 1.8. Otherwise, there is no way to fake only the initial 
migrations for the auth and contenttypes apps if you've already upgraded to 
Django 1.8 (perhaps there should be?).

Tobias

On Saturday, July 18, 2015 at 12:42:57 PM UTC-4, Chris DiLorenzo wrote:
>
> While poking around with this again, I noticed that the thing causing the 
> error for me was a datamigration (being applied due to it being run in 
> tests) which is (I believe) why I was seeing the issue when trying to run 
> tests but not otherwise. I was trying to grab a contenttype using 
> ContentType.objects.get_for_model(MODEL). So my current belief is that no 
> ContentType was created for that MODEL before that datamigration was run, 
> thus causing it to fail the creation causing the error. Hope that helps.
>
> On Wednesday, July 15, 2015 at 10:43:54 PM UTC+2, Tomas Henriquez wrote:
>>
>> I just fixed this issue by entering into my database directly, showed all 
>> rows on "django_migrations", I saw that I did migrated before the 
>> contenttypes (probably when I did a regression to django 1.4 for some 
>> tests). By deleting the rows with contenttypes on it, deleting the 
>> contenttypes table and running the migration again I was able to fix the 
>> issue.
>>
>> On Wednesday, July 15, 2015 at 3:30:27 PM UTC-4:30, Chris DiLorenzo wrote:
>>>
>>> Hey Devang,
>>>
>>> No, we did not fake any migrations =(
>>>
>>> On Tuesday, June 23, 2015 at 12:58:46 AM UTC+2, Devang Mundhra wrote:

 Chris-
 By any chance, did you fake any of the migrations. That was the problem 
 I had faced- it wasn't a Django problem, it was a problem with my 
 migration.

 On Mon, Jun 22, 2015 at 3:52 PM Chris DiLorenzo <
 dilorenzo@gmail.com> wrote:

> I'm seeing this issue as well. Not sure if it helps but I get it when 
> running my tests.
>
> I chose to raise the error instead and saw this:
>
> django.db.utils.IntegrityError: null value in column "name" violates 
> not-null
> constraint
> DETAIL:  Failing row contains (1, null, app, listing).
>
>
> Where app is the django app name and listing is the model name. So 
> that sounds to me like I'm seeing what everyone else is, the migration is 
> just not applied on the database for some reason, but shows as being 
> applied OK.
>
> // Chris
>
>
> On Wednesday, June 10, 2015 at 11:31:42 AM UTC-4, Devang Mundhra wrote:
>
>> In my case this is not a Django bug.
>> The problem was that since 1.8 contenttypes started to have 
>> migrations. But since the table already existed earlier, the migrations 
>> needed to be faked.
>> When faking the migrations, I used python manage.py migrate 
>> contenttypes --fake which faked both 0001 and 0002.
>>
>> The fix was to remove the fake migration for 0002 from 
>> django_migrations table and then do the actual migration.
>>
>> On Wed, Jun 10, 2015 at 6:57 AM Tim Graham  
>> wrote:
>>
> If anyone running into this problem can figure out why the 
>>> contrib.contenttypes migration (0002_remove_content_type_name) is being 
>>> marked as applied but not actually run in the database, that will help 
>>> determine if this is a bug in Django or a problem elsewhere.
>>>
>>>
>>> On Wednesday, June 10, 2015 at 7:11:48 AM UTC-4, Devang Mundhra 
>>> wrote:

 I am getting the same error on Django v1.8.2 after migrating from 
 v1.7.7
 The underlying error is this-

 django.db.utils.IntegrityError: null value in column "name" 
> violates not-null constraint
> DETAIL:  Failing row contains (39, null, app_name, model_name).
>
>
 On Friday, April 17, 2015 at 1:25:06 PM UTC-7, Tim Graham wrote:
>
> The contenttypes name column was removed in Django 1.8. Could you 
> retrieve the underlying exception before the RuntimeError is raised?
>
> On Friday, April 17, 2015 at 2:55:07 PM UTC-4, Christophe Pettus 
> wrote:
>>
>> Digging into this a bit more, the specific exception is that it 
>> is trying to insert a contenttypes row with a null 'name' value. 
>>
>> The code in question is doing a get_or_create() on the 
>> contenttype object.  I assume it should be picking up the name from 
>> the 
>> name @property on the ContentType model, but I don't see that ever 
>> actually 
>> being called. 
>>
>>
>> On Apr 17, 2015, at 11:24 AM, Christophe Pettus <
>> 

URL Generation

2015-07-26 Thread James Schneider
Hello all,

I have an issue that I've been trying to work around in a generic fashion
(so that I'm not repeating myself in views/templates). Let's say I have
three models:

# models
class Organization(models.Model):
name = models.CharField(max_length=250, null=False, blank=False,
unique=True)


class Team(models.Model):
organization = models.ForeignKey(Organization, null=False)
name = models.CharField(max_length=250)


class Competition(models.Model):
organization = models.ForeignKey(Organization, null=False)
name = models.CharField(max_length=250)
teams = models.ManyToManyField(Team, related_name='competitions')


And this basic URL structure:

# urls

# organization URL's
url(
regex=r'organization/',
view=include(organization_urlpatterns, namespace='organization'),
),

# team URL's
url(
regex=r'organization/(?P\d+)/team/',
view=include('project.teams.urls', namespace='team'),
),

# competition URL's
url(
regex=r'organization/(?P\d+)/competition/',
view=include('project.competitions.urls', namespace='competition'),
),


# competition team listing - project.competitions.urls
url(
regex=r'^(?P\d+)/team/',
view=include('project.teams.urls', namespace='team'),
),


In this (simplified version of my) application, a Team is a member of an
Organization. Competitions are created within the Organization, and will
have one or more Teams associated with them. Teams can be associated with
multiple Competitions, but not with multiple Organizations.

Focusing on Teams specifically, there are two URL's/views that can be used
to view a Team. One from the perspective of an Organizatoin (where you can
see all of the teams associated with an Organization), and one within the
context of a Competition, where you can see a list of Teams filtered
specifically for that Competition.

Here's my dilemma. I need to generate various links to get to other parts
of the application, but if the user is working within the 'context' of a
competition (adding/removing teams, etc.), then I need the links for
objects to be relative to the Competition that they are working on. For
example, a link to 'list all teams' in the Organization context should list
all of the teams within an Organization, but should be limited to the
associated teams in a Competition context (using the term context
generally, not referring to a template context).

Normally I would use something like get_absolute_url() on the model, but
the model object has no concept of the 'context' of where/how it is being
modified, so get_absolute_url() would unconditionally return the URL as if
it were being viewed at an Organizational level, meaning that all of the
links would take the user out of the context where they were expecting, and
force them to navigate back into it.

I have several other models that need to follow a similar URL scheme, so
something generic would be appreciated.

I have a sneaking suspicion that utilizing app_name within the URL's could
be beneficial, but I can't seem to grasp the concept of how to properly use
an app_name with URL's, and have it apply to my situation (I'm already
using instance namepaces, which have been working out peachy so far). It'd
be nice to just have 'team:create' as the namespace and have Django
automagically determine whether or not it should stay within the
Comeptition context. The other wrinkle in this is that any operations
performed in the Competition context currently require an extra kwarg
(competition_pk) to specify what Competition is in use, whereas both URL's
are already aware of the Organization (organization_pk). I'm open to
reworking the URL structure if someone can point me in the right direction
and that is the only hurdle.

What URL resolution strategies would be appropriate in this situation?

Thank you in advance,

-James

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUQtquvkdYa3JHe_8QxpSfrH9AnkmrR9d8siJCjd-hZtA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: "RuntimeError: Error creating new content types."

2015-07-26 Thread Allen Romero
Good tip. First upgrading to Django 1.7 then running the migrations then 
upgrading to 1.8 also fixed this for me :)

On Sunday, July 26, 2015 at 9:50:19 AM UTC-7, Tobias McNulty wrote:
>
> I just ran into this issue as well when updating an old project to Django 
> 1.8. The only suitable workaround I found was to update first to Django 1.7 
> and fake the initial migrations for my apps (presumably Django's as well, 
> though it seems to handle that automatically). Only then can you safely 
> update to Django 1.8. Otherwise, there is no way to fake only the initial 
> migrations for the auth and contenttypes apps if you've already upgraded to 
> Django 1.8 (perhaps there should be?).
>
> Tobias
>
> On Saturday, July 18, 2015 at 12:42:57 PM UTC-4, Chris DiLorenzo wrote:
>>
>> While poking around with this again, I noticed that the thing causing the 
>> error for me was a datamigration (being applied due to it being run in 
>> tests) which is (I believe) why I was seeing the issue when trying to run 
>> tests but not otherwise. I was trying to grab a contenttype using 
>> ContentType.objects.get_for_model(MODEL). So my current belief is that no 
>> ContentType was created for that MODEL before that datamigration was run, 
>> thus causing it to fail the creation causing the error. Hope that helps.
>>
>> On Wednesday, July 15, 2015 at 10:43:54 PM UTC+2, Tomas Henriquez wrote:
>>>
>>> I just fixed this issue by entering into my database directly, showed 
>>> all rows on "django_migrations", I saw that I did migrated before the 
>>> contenttypes (probably when I did a regression to django 1.4 for some 
>>> tests). By deleting the rows with contenttypes on it, deleting the 
>>> contenttypes table and running the migration again I was able to fix the 
>>> issue.
>>>
>>> On Wednesday, July 15, 2015 at 3:30:27 PM UTC-4:30, Chris DiLorenzo 
>>> wrote:

 Hey Devang,

 No, we did not fake any migrations =(

 On Tuesday, June 23, 2015 at 12:58:46 AM UTC+2, Devang Mundhra wrote:
>
> Chris-
> By any chance, did you fake any of the migrations. That was the 
> problem I had faced- it wasn't a Django problem, it was a problem with my 
> migration.
>
> On Mon, Jun 22, 2015 at 3:52 PM Chris DiLorenzo <
> dilorenzo@gmail.com> wrote:
>
>> I'm seeing this issue as well. Not sure if it helps but I get it when 
>> running my tests.
>>
>> I chose to raise the error instead and saw this:
>>
>> django.db.utils.IntegrityError: null value in column "name" violates 
>> not-null
>> constraint
>> DETAIL:  Failing row contains (1, null, app, listing).
>>
>>
>> Where app is the django app name and listing is the model name. So 
>> that sounds to me like I'm seeing what everyone else is, the migration 
>> is 
>> just not applied on the database for some reason, but shows as being 
>> applied OK.
>>
>> // Chris
>>
>>
>> On Wednesday, June 10, 2015 at 11:31:42 AM UTC-4, Devang Mundhra 
>> wrote:
>>
>>> In my case this is not a Django bug.
>>> The problem was that since 1.8 contenttypes started to have 
>>> migrations. But since the table already existed earlier, the migrations 
>>> needed to be faked.
>>> When faking the migrations, I used python manage.py migrate 
>>> contenttypes --fake which faked both 0001 and 0002.
>>>
>>> The fix was to remove the fake migration for 0002 from 
>>> django_migrations table and then do the actual migration.
>>>
>>> On Wed, Jun 10, 2015 at 6:57 AM Tim Graham  
>>> wrote:
>>>
>> If anyone running into this problem can figure out why the 
 contrib.contenttypes migration (0002_remove_content_type_name) is 
 being 
 marked as applied but not actually run in the database, that will help 
 determine if this is a bug in Django or a problem elsewhere.


 On Wednesday, June 10, 2015 at 7:11:48 AM UTC-4, Devang Mundhra 
 wrote:
>
> I am getting the same error on Django v1.8.2 after migrating from 
> v1.7.7
> The underlying error is this-
>
> django.db.utils.IntegrityError: null value in column "name" 
>> violates not-null constraint
>> DETAIL:  Failing row contains (39, null, app_name, model_name).
>>
>>
> On Friday, April 17, 2015 at 1:25:06 PM UTC-7, Tim Graham wrote:
>>
>> The contenttypes name column was removed in Django 1.8. Could you 
>> retrieve the underlying exception before the RuntimeError is raised?
>>
>> On Friday, April 17, 2015 at 2:55:07 PM UTC-4, Christophe Pettus 
>> wrote:
>>>
>>> Digging into this a bit more, the specific exception is that it 
>>> is trying to insert a contenttypes row with a null 'name' value. 
>>>
>>> The code in question is doing a get