Re: django Object not iterable error

2015-06-15 Thread Shekar Tippur

>
> Thank you! Thank you! Thank you!


Sometimes I miss the most obvious things.

Thanks again.

- Shekar 

-- 
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/682c0bd1-1937-4348-a2c3-a1dc2d969081%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add multiple objects of same model at the same time in admin

2015-06-15 Thread Robin Lery
Thank you.

On Mon, Jun 15, 2015 at 10:37 PM, carlos  wrote:

> Hello, use two model and the second model inline one model example
>
> class ModelA(...):
> name = charfield(...)
>
> class ModelB():
> fk(ModelA)
>image = imagefiel(...)
>caption = bla bla bla
>   date = datefield
>
> and them in admin.py
>
> class ModelBInline(admin.TabularInline):
> model = ModelB
> extra = 1
>
> class ModelAAdmin(admin.ModelAdmin):
> inlines = [ModelBInline]
>
> admin.site.register(ModelA, ModelAAdmin)
>
> Cheers
>
>
>
>
>
>
> On Sun, Jun 14, 2015 at 1:08 AM, Carlos Arturo Sanchez Rivera <
> ing.c...@gmail.com> wrote:
>
>> It is easier with decorators
>>
>> @admin.register(Transfer)
>> class TransferAdmin(admin.ModelAdmin):
>> pass
>>
>>
>>
>> El sábado, 13 de junio de 2015, 4:28:38 (UTC-5), Robin Lery escribió:
>>>
>>> I have a model to upload pictures:
>>>
>>> models.py:
>>>
>>>
 class Snap(models.Model):
 image = models.ImageField(upload_to=get_upload_file_name)
 caption = models.CharField(max_length=150, blank=True, null=True)
 date = models.DateField(default=date.today)

>>>
>>> admin.py:
>>>
>>> class SnapAdmin(admin.ModelAdmin):
 class Meta:
 model = Snap

 admin.site.register(Snap, SnapAdmin)

>>>
>>> In the admin it contains all the Snap's field (i.e. one field to upload
>>> an image ,its caption and the pubdate) which is as expected. How do I add
>>> multiple record of Snap's in one go, without having to save it one by
>>> one. I hope I was clear, if not please ask. Your help and guidance will be
>>> very much appreciated. Thank you.
>>>
>>  --
>> 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/5f3a3841-6605-4250-9299-ff4922c8421f%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/CAM-7rO3ubHWOHVJT6wMjxrPag9G1-OBXDGev9g-RG8PWakzUtQ%40mail.gmail.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/CA%2B4-nGrbmmOrgCxjSUGdmwhBbbugvk%3DOYEBi-SXfswiNm5nS%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django Object not iterable error

2015-06-15 Thread James Schneider
That is what I meant, but the extra code is quite helpful. In your
urls.py file you have this:

url(r'^product/$', productviews, productviews.ProductList.as_view()),

when you probably want this:

url(r'^product/$', productviews.ProductList.as_view()),


You have an extra reference to 'productviews' as the second argument,
which makes the URL resolver unhappy since it is now trying to execute
the whole productviews module as a function.

-James

On Mon, Jun 15, 2015 at 5:58 PM, Shekar Tippur  wrote:
> Here my urls.py
>
> urlpatterns = [
> url(r'^admin/', include(admin.site.urls)),
> url(r'^product/$', productviews, productviews.ProductList.as_view()),
> url(r'^product/(?P[0-9]+)$', productviews.ProductDetail.as_view()),
> ]
>
>
> productviews.py
>
>
> from product.models import Product
> from product.serializers import ProductSerializer
> from rest_framework import generics
> from django.views.decorators.csrf import csrf_exempt
> from django.utils.decorators import method_decorator
> from django.http import HttpResponse
> import json
>
>
> class ProductList(generics.ListCreateAPIView):
> queryset = Product
> serializer_class = ProductSerializer
> @method_decorator(csrf_exempt)
> def post(self, request, *args, **kwargs):
> received_json_data=json.loads(request.body.decode("utf8"))
> serializer = ProductSerializer(data=received_json_data)
> if serializer.is_valid():
> serializer.save()
> print (request.body)
> return HttpResponse('SUCCESS')
> else:
> print (serializer.errors)
> return HttpResponse('Error')
>
> --
> 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/3bd15344-357e-4a6c-a7a1-0a7ad5a1131d%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/CA%2Be%2BciWMqxLb4fOB3kSGRckMiBrJm8%3DSEUHHY%2BjfVe40N4wSEQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django Object not iterable error

2015-06-15 Thread Shekar Tippur
Here my urls.py

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^product/$', productviews, productviews.ProductList.as_view()),
url(r'^product/(?P[0-9]+)$', productviews.ProductDetail.as_view()),
]


*productviews.py*


from product.models import Product
from product.serializers import ProductSerializer
from rest_framework import generics
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator
from django.http import HttpResponse
import json


class ProductList(generics.ListCreateAPIView):
queryset = Product
serializer_class = ProductSerializer
@method_decorator(csrf_exempt)
def post(self, request, *args, **kwargs):
received_json_data=json.loads(request.body.decode("utf8"))
serializer = ProductSerializer(data=received_json_data)
if serializer.is_valid():
serializer.save()
print (request.body)
return HttpResponse('SUCCESS')
else:
print (serializer.errors)
return HttpResponse('Error')

-- 
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/3bd15344-357e-4a6c-a7a1-0a7ad5a1131d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django Object not iterable error

2015-06-15 Thread Vijay Khemlani
No, you need to post the parts of your code that may have triggered the
error.

In this case, your urls.py and the method in your views.py that handles the
request probably.

On Mon, Jun 15, 2015 at 9:32 PM, Shekar Tippur  wrote:

> James,
>
> Is this what you mean?
>
> - Shekar
>
>
>> Environment:Request Method: POSTRequest URL: 
>> http://127.0.0.1:8000/product/Django Version: 1.8.2Python Version: 
>> 3.4.3Installed Applications:('django.contrib.admin', 'django.contrib.auth', 
>> 'django.contrib.contenttypes', 'django.contrib.sessions', 
>> 'django.contrib.messages', 'django.contrib.staticfiles', 
>> 'product',)Installed Middleware:('disable.DisableCSRF', 
>> 'django.contrib.sessions.middleware.SessionMiddleware', 
>> 'django.middleware.common.CommonMiddleware', 
>> 'django.middleware.csrf.CsrfViewMiddleware', 
>> 'django.contrib.auth.middleware.AuthenticationMiddleware', 
>> 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
>> 'django.contrib.messages.middleware.MessageMiddleware', 
>> 'django.middleware.clickjacking.XFrameOptionsMiddleware', 
>> 'django.middleware.security.SecurityMiddleware')Traceback:File 
>> "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/handlers/base.py"
>>  in get_response  119. resolver_match = 
>> resolver.resolve(request.path_info)File 
>> "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/urlresolvers.py"
>>  in resolve  368. sub_match = 
>> pattern.resolve(new_path)File 
>> "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/urlresolvers.py"
>>  in resolve  238. kwargs.update(self.default_args)Exception 
>> Type: TypeError at /product/Exception Value: 'function' object is not 
>> iterable
>>>
>>>   --
> 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/a5df84ec-2d2f-47ef-bdef-4cbbfaa7406b%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/CALn3ei0WdSBgfSwnnFGcp%2BacFQMm0AXyTFbf4fWOLLnBhf%2B9_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django Object not iterable error

2015-06-15 Thread Shekar Tippur
James,

Is this what you mean?

- Shekar
 

> Environment:Request Method: POSTRequest URL: 
> http://127.0.0.1:8000/product/Django Version: 1.8.2Python Version: 
> 3.4.3Installed Applications:('django.contrib.admin', 'django.contrib.auth', 
> 'django.contrib.contenttypes', 'django.contrib.sessions', 
> 'django.contrib.messages', 'django.contrib.staticfiles', 'product',)Installed 
> Middleware:('disable.DisableCSRF', 
> 'django.contrib.sessions.middleware.SessionMiddleware', 
> 'django.middleware.common.CommonMiddleware', 
> 'django.middleware.csrf.CsrfViewMiddleware', 
> 'django.contrib.auth.middleware.AuthenticationMiddleware', 
> 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
> 'django.contrib.messages.middleware.MessageMiddleware', 
> 'django.middleware.clickjacking.XFrameOptionsMiddleware', 
> 'django.middleware.security.SecurityMiddleware')Traceback:File 
> "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/handlers/base.py"
>  in get_response  119. resolver_match = 
> resolver.resolve(request.path_info)File 
> "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/urlresolvers.py"
>  in resolve  368. sub_match = 
> pattern.resolve(new_path)File 
> "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/urlresolvers.py"
>  in resolve  238. kwargs.update(self.default_args)Exception Type: 
> TypeError at /product/Exception Value: 'function' object is not iterable
>>
>> 

-- 
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/a5df84ec-2d2f-47ef-bdef-4cbbfaa7406b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django Object not iterable error

2015-06-15 Thread James Schneider
Can you post the entire stack trace? You may have to run a bit up the chain
in the race to track down the problem.

-James
On Jun 15, 2015 2:40 PM, "Shekar Tippur"  wrote:

>
>
>
> Hello,
>
> This maybe a generic question. How do I troubleshoot something like this.
> The stacktrace is not really helpful as it does not point to the code that
> is causing this issue.
>
> TypeError at /product/
>
> 'function' object is not iterable
>
> Request Method:POSTRequest URL:http://127.0.0.1:8000/product/Django
> Version:1.8.2Exception Type:TypeErrorException Value:
>
> 'function' object is not iterable
>
> Exception 
> Location:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/urlresolvers.py
> in resolve, line 238Python Executable:
> /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4Python
> Version:3.4.3Python Path:
>
> ['/Users/ctippur/PycharmProjects/project1',
>  '/Users/ctippur/PycharmProjects/project1',
>  '/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip',
>  '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4',
>  
> '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin',
>  
> '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload',
>  
> '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages'
>
>
> - Shekar
>
>  --
> 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/3d689375-1afe-448e-95b4-54ecbab2cd77%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/CA%2Be%2BciVh7fmPgHuvD9KHjDz6pSJG2zoa1dsW1PffvBf%3DUV4iqQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django plugin

2015-06-15 Thread Mario Gudelj
You can use celery and periodic tasks to scan for new orders every 5
minutes and send email notification of the new order is there.
On 12 Jun 2015 6:59 pm, "'Tom Evans' via Django users" <
django-users@googlegroups.com> wrote:

> On Thu, Jun 11, 2015 at 8:02 PM, Andreas Kuhne
>  wrote:
> > Hi all,
> >
> > I was wondering if there is a plugin application for Django. What I want
> to
> > accomplish is react to different kinds of events on my models and then
> > create plugins on the fly for them.
> >
> > The system I am working on has for example an Order model. When a new
> Order
> > is created, I want to send a notification to the person who created the
> > order. I know that I can do this with signals, but I don't want it to
> > specifically be tied to a Django application.
> >
> > I was thinking something along the lines of using RabbitMQ for example to
> > post all events there and then be able to react on them later. Has anyone
> > done anything like this?
> >
> > I have seen Celery, but as I understand that, it takes some method to run
> > like a delayed job?
> >
> > Regards,
> >
> > Andréas
> >
>
> Celery is (usually) built on top of an AMQP broker. AMQP was developed
> to support High Frequency Trading (HFT) and is ideal for publishing
> events and taking actions based upon them. I'd suggest reading this
> blog post:
>
> http://blogs.digitar.com/jjww/2009/01/rabbits-and-warrens/
>
> and then the docs for Kombu, which is an excellent messaging library for
> python.
>
> http://kombu.readthedocs.org/en/latest/
>
> AMQP is not the only message bus, but we've had great results with it
> (using rabbitmq).
>
> Cheers
>
> Tom
>
> --
> 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/CAFHbX1JEb08O0PMdzEBC0%3Dq8LRVZcHz11PPg067aSby7YhaLjQ%40mail.gmail.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/CAHqTbjnJL1SzdPYjZmTL2-TVyJTW9Lv_9vo%3DfgjUyHT876M_3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


django Object not iterable error

2015-06-15 Thread Shekar Tippur



Hello,

This maybe a generic question. How do I troubleshoot something like this. 
The stacktrace is not really helpful as it does not point to the code that 
is causing this issue.

TypeError at /product/

'function' object is not iterable

Request Method:POSTRequest URL:http://127.0.0.1:8000/product/Django Version:
1.8.2Exception Type:TypeErrorException Value:

'function' object is not iterable

Exception 
Location:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/urlresolvers.py
 
in resolve, line 238Python Executable:
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4Python 
Version:3.4.3Python Path:

['/Users/ctippur/PycharmProjects/project1',
 '/Users/ctippur/PycharmProjects/project1',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload',
 '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages'


- Shekar

-- 
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/3d689375-1afe-448e-95b4-54ecbab2cd77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Add multiple objects of same model at the same time in admin

2015-06-15 Thread carlos
Hello, use two model and the second model inline one model example

class ModelA(...):
name = charfield(...)

class ModelB():
fk(ModelA)
   image = imagefiel(...)
   caption = bla bla bla
  date = datefield

and them in admin.py

class ModelBInline(admin.TabularInline):
model = ModelB
extra = 1

class ModelAAdmin(admin.ModelAdmin):
inlines = [ModelBInline]

admin.site.register(ModelA, ModelAAdmin)

Cheers






On Sun, Jun 14, 2015 at 1:08 AM, Carlos Arturo Sanchez Rivera <
ing.c...@gmail.com> wrote:

> It is easier with decorators
>
> @admin.register(Transfer)
> class TransferAdmin(admin.ModelAdmin):
> pass
>
>
>
> El sábado, 13 de junio de 2015, 4:28:38 (UTC-5), Robin Lery escribió:
>>
>> I have a model to upload pictures:
>>
>> models.py:
>>
>>
>>> class Snap(models.Model):
>>> image = models.ImageField(upload_to=get_upload_file_name)
>>> caption = models.CharField(max_length=150, blank=True, null=True)
>>> date = models.DateField(default=date.today)
>>>
>>
>> admin.py:
>>
>> class SnapAdmin(admin.ModelAdmin):
>>> class Meta:
>>> model = Snap
>>>
>>> admin.site.register(Snap, SnapAdmin)
>>>
>>
>> In the admin it contains all the Snap's field (i.e. one field to upload
>> an image ,its caption and the pubdate) which is as expected. How do I add
>> multiple record of Snap's in one go, without having to save it one by
>> one. I hope I was clear, if not please ask. Your help and guidance will be
>> very much appreciated. Thank you.
>>
>  --
> 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/5f3a3841-6605-4250-9299-ff4922c8421f%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/CAM-7rO3ubHWOHVJT6wMjxrPag9G1-OBXDGev9g-RG8PWakzUtQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Get the first image src from a post

2015-06-15 Thread Robert librado
very nice work

On 6/15/15, Vijay Khemlani  wrote:
> If the description is stored as HTML I guess you could use something like
> BeautifulSoup or pyquery to parse it and find the tag
>
> from bs4 import BeautifulSoup
>
> soup = BeautifulSoup(blog.description)
> image_src = soup.find('img')['src']
>
>
> On Mon, Jun 15, 2015 at 8:59 AM, Robin Lery  wrote:
>
>> I have a model to write blogs. In that I'm using a wysiwyg editor for the
>> Blog's descritpion, through which I can insert an image within the
>> description.
>>
>> class Blog(models.Model):
>> title = models.CharField(max_length=150, blank=True)
>> description = models.TextField()
>> pubdate = models.DateTimeField(default=timezone.now)
>> publish = models.BooleanField(default=False)
>>
>> In the admin it looks like this:
>>
>> [image: enter image description here]
>>
>> What I want is to get first image inside the description of the blog, and
>> present it in the template like this:
>>
>> [image: enter image description here]
>>
>> How do get the img src from the description of the blog to use it in the
>> template? Your help and guidance will be very much appreciated. Thank
>> you.
>>
>> views.py:
>>
>> def blog(request):
>> blogs = Blog.objects.all()
>>
>> return render(request, 'blogs.html', {
>> 'blogs':blogs
>> })
>>
>> template:
>>
>>   {% for blog in blogs %}
>>   
>>{{blog.pubdate}} 
>>{{blog.title}} 
>>   > class="blog_image img-responsive img-thumbnail">
>>
>>
>>   Read more
>>   
>>   ***
>>   
>>   
>>   {% endfor %}
>>
>>  --
>> 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%2B4-nGo4ZJmArnQ2nvF5f0tp83HA7LJTxdywtO8%2BxsBVp2211g%40mail.gmail.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/CALn3ei242vCJfTSrUtWTKbNO%2BXCDkPdn7pOJzN%3DhkXoR0CjT5Q%40mail.gmail.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/CAAmfpZ3O6tEEHS1-3rnCAABFOszYrMFUEtBSh1COy1DuoVrMhA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Squashed migration

2015-06-15 Thread aRkadeFR

Great.

Thanks for the feedback :)

On 06/15/2015 02:18 PM, Cherie Pun wrote:

Hi,

So the original problem was that I was running in the repo which 
didn't have the squashed migration. Django does know when to switch to 
the squashed migrations when you have both squashed and unsquashed 
migration files coexist in the folder.
As for the syntax error it was because python cannot import from 
modules that starts with numbers. Also, the idea was that we shouldn't 
use the migration files as modules to import code from, that's why the 
file name stayed as it was. Users should manually move their RunPython 
methods manually and resolve those invalid references to migration files.


Hope this helps and sorry for confusing people that squash migration 
doesn't work! I am still new to Python and Django and I really 
appreciate everyone's replies.


Cheers,
Cherie

On Monday, June 15, 2015 at 9:54:09 AM UTC+1, aRkadeFR wrote:

Thanks for the good explanation as always :)

 From the documentation plus the explanation of the problem,
I wanted to know if by deleting the old migration it would still
run the old migrations.

Do we know the end of the story? Where it comes from?

Thanks

On 06/12/2015 05:42 PM, Carl Meyer wrote:
> On 06/12/2015 06:32 AM, aRkadeFR wrote:
>> You need to delete your old migrations so it uses only the
squashed
>> one after.
> No, the squashed migration should be used in place of the old
ones for
> any new database, even if the old ones are still present. This
is the
> point of the squashmigrations feature; that you can keep the old
ones
> around (which is necessary for any deployments that may not yet
have
> applied all of them) while still gaining the benefit of the new
squashed
> migration for new deployments (and tests).
>
> I know this works, because I just did it recently myself. It
sounds like
> Cherie was able to get it working too, though we didn't get any
> clarification on why it didn't seem to work originally.
>
>> In the documentation:
>> "This enables you to squash and not mess up systems currently in
>> production that aren’t fully up-to-date yet. The recommended
process is
>> to squash, keeping the old files, commit and release, wait
until all
>> systems are upgraded with the new release (or if you’re a
third-party
>> project, just ensure your users upgrade releases in order without
>> skipping any), and then remove the old files, commit and do a
second
>> release."
> That's right. The length of time you need to wait before
removing can
> vary widely. For a third-party app, it may be a full release
cycle or
> two (as long as you can tell your users to upgrade
version-by-version).
> For a project with only a few deployments, all under your
control, it
> may be the same day. But regardless, the squashed migration will
still
> be used in tests immediately, before you remove the old migrations.
>
> Carl
>

-- 
aRkadeFR


--
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/a46519d9-3819-40d5-8a18-236a4bec846e%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
aRkadeFR

--
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/557EC915.4020408%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Re: Get the first image src from a post

2015-06-15 Thread Vijay Khemlani
If the description is stored as HTML I guess you could use something like
BeautifulSoup or pyquery to parse it and find the tag

from bs4 import BeautifulSoup

soup = BeautifulSoup(blog.description)
image_src = soup.find('img')['src']


On Mon, Jun 15, 2015 at 8:59 AM, Robin Lery  wrote:

> I have a model to write blogs. In that I'm using a wysiwyg editor for the
> Blog's descritpion, through which I can insert an image within the
> description.
>
> class Blog(models.Model):
> title = models.CharField(max_length=150, blank=True)
> description = models.TextField()
> pubdate = models.DateTimeField(default=timezone.now)
> publish = models.BooleanField(default=False)
>
> In the admin it looks like this:
>
> [image: enter image description here]
>
> What I want is to get first image inside the description of the blog, and
> present it in the template like this:
>
> [image: enter image description here]
>
> How do get the img src from the description of the blog to use it in the
> template? Your help and guidance will be very much appreciated. Thank you.
>
> views.py:
>
> def blog(request):
> blogs = Blog.objects.all()
>
> return render(request, 'blogs.html', {
> 'blogs':blogs
> })
>
> template:
>
>   {% for blog in blogs %}
>   
>{{blog.pubdate}} 
>{{blog.title}} 
>   
>
>
>   Read 
> more
>   
>   ***
>   
>   
>   {% endfor %}
>
>  --
> 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%2B4-nGo4ZJmArnQ2nvF5f0tp83HA7LJTxdywtO8%2BxsBVp2211g%40mail.gmail.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/CALn3ei242vCJfTSrUtWTKbNO%2BXCDkPdn7pOJzN%3DhkXoR0CjT5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Squashed migration

2015-06-15 Thread Cherie Pun
Hi,

So the original problem was that I was running in the repo which didn't 
have the squashed migration. Django does know when to switch to the 
squashed migrations when you have both squashed and unsquashed migration 
files coexist in the folder.
As for the syntax error it was because python cannot import from modules 
that starts with numbers. Also, the idea was that we shouldn't use the 
migration files as modules to import code from, that's why the file name 
stayed as it was. Users should manually move their RunPython methods 
manually and resolve those invalid references to migration files.

Hope this helps and sorry for confusing people that squash migration 
doesn't work! I am still new to Python and Django and I really appreciate 
everyone's replies.

Cheers,
Cherie

On Monday, June 15, 2015 at 9:54:09 AM UTC+1, aRkadeFR wrote:
>
> Thanks for the good explanation as always :) 
>
>  From the documentation plus the explanation of the problem, 
> I wanted to know if by deleting the old migration it would still 
> run the old migrations. 
>
> Do we know the end of the story? Where it comes from? 
>
> Thanks 
>
> On 06/12/2015 05:42 PM, Carl Meyer wrote: 
> > On 06/12/2015 06:32 AM, aRkadeFR wrote: 
> >> You need to delete your old migrations so it uses only the squashed 
> >> one after. 
> > No, the squashed migration should be used in place of the old ones for 
> > any new database, even if the old ones are still present. This is the 
> > point of the squashmigrations feature; that you can keep the old ones 
> > around (which is necessary for any deployments that may not yet have 
> > applied all of them) while still gaining the benefit of the new squashed 
> > migration for new deployments (and tests). 
> > 
> > I know this works, because I just did it recently myself. It sounds like 
> > Cherie was able to get it working too, though we didn't get any 
> > clarification on why it didn't seem to work originally. 
> > 
> >> In the documentation: 
> >> "This enables you to squash and not mess up systems currently in 
> >> production that aren’t fully up-to-date yet. The recommended process is 
> >> to squash, keeping the old files, commit and release, wait until all 
> >> systems are upgraded with the new release (or if you’re a third-party 
> >> project, just ensure your users upgrade releases in order without 
> >> skipping any), and then remove the old files, commit and do a second 
> >> release." 
> > That's right. The length of time you need to wait before removing can 
> > vary widely. For a third-party app, it may be a full release cycle or 
> > two (as long as you can tell your users to upgrade version-by-version). 
> > For a project with only a few deployments, all under your control, it 
> > may be the same day. But regardless, the squashed migration will still 
> > be used in tests immediately, before you remove the old migrations. 
> > 
> > Carl 
> > 
>
> -- 
> aRkadeFR 
>
>

-- 
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/a46519d9-3819-40d5-8a18-236a4bec846e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Get the first image src from a post

2015-06-15 Thread Robin Lery
I have a model to write blogs. In that I'm using a wysiwyg editor for the
Blog's descritpion, through which I can insert an image within the
description.

class Blog(models.Model):
title = models.CharField(max_length=150, blank=True)
description = models.TextField()
pubdate = models.DateTimeField(default=timezone.now)
publish = models.BooleanField(default=False)

In the admin it looks like this:

[image: enter image description here]

What I want is to get first image inside the description of the blog, and
present it in the template like this:

[image: enter image description here]

How do get the img src from the description of the blog to use it in the
template? Your help and guidance will be very much appreciated. Thank you.

views.py:

def blog(request):
blogs = Blog.objects.all()

return render(request, 'blogs.html', {
'blogs':blogs
})

template:

  {% for blog in blogs %}
  
   {{blog.pubdate}} 
   {{blog.title}} 
  


  Read more
  
  ***
  
  
  {% endfor %}

-- 
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%2B4-nGo4ZJmArnQ2nvF5f0tp83HA7LJTxdywtO8%2BxsBVp2211g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: potential bug

2015-06-15 Thread Mark Nesterovych
Forgot about ModelChoise.
Thank you.

On Sunday, 14 June 2015 22:37:26 UTC+3, Tom Evans wrote:
>
> On Sun, Jun 14, 2015 at 3:24 PM, Mark Nesterovych 
>  wrote: 
> > Hello. 
> > I've just finished small django site, and keep going on creating tests. 
> > I've found and issue with Model.objects.values_list  method. 
> > Looks like it disregard test database and looks into production one. 
> > 
> > Some details. 
> > I have a form with a filed customer = 
> > forms.ChoiseField(choises=Customer.objects.values_list('id', 'name')) 
> > 
> > When this form initing during tests, it loads data from production 
> database. 
> > 
> > My test looks like this. 
> > class CustomerFormTest(TestCase): 
> > def setUp: 
> >  self.customer = Customer.objects.create(name='test name') 
> > 
> > def test_form_creation(self): 
> > form = CustomerLoginForm() 
> > self.assertIn('test name', form.as_ul()) 
> > 
> > 
> > Assertion fails, and when I printing form content, I see select widget 
> with 
> > options from production database objects. 
> > 
> > Can somebody confirm it's a bug ? 
> > Thank you. 
>
> It's not a bug. You are specifying the choices when the form is 
> defined, and at that point there is nothing in the database and so the 
> form has no choices. Since the field is never redefined in the form, 
> the choices will be whatever existed in the database when the form is 
> defined, which is a bad way of designing the form. 
>
> Typically, when your choices are instances of a model, you would not 
> use ChoiceField, but ModelChoicefield. ModelChoiceField takes a 
> queryset when defining the form, and avoids evaluating the queryset 
> until the form is instantiated, which avoids the issue. The 
> documentation also explains how you can specify the queryset more 
> dynamically if that is required. 
>
> https://docs.djangoproject.com/en/1.8/ref/forms/fields/#modelchoicefield 
>
> (I'm assuming that the typo "choises" is only present in your email, 
> and your code correctly says "choices" and "ChoiceField") 
>
> Cheers 
>
> Tom 
>

-- 
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/64b6f961-3ad5-4b06-ac35-a5590c9c1de5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Squashed migration

2015-06-15 Thread aRkadeFR

Thanks for the good explanation as always :)

From the documentation plus the explanation of the problem,
I wanted to know if by deleting the old migration it would still
run the old migrations.

Do we know the end of the story? Where it comes from?

Thanks

On 06/12/2015 05:42 PM, Carl Meyer wrote:

On 06/12/2015 06:32 AM, aRkadeFR wrote:

You need to delete your old migrations so it uses only the squashed
one after.

No, the squashed migration should be used in place of the old ones for
any new database, even if the old ones are still present. This is the
point of the squashmigrations feature; that you can keep the old ones
around (which is necessary for any deployments that may not yet have
applied all of them) while still gaining the benefit of the new squashed
migration for new deployments (and tests).

I know this works, because I just did it recently myself. It sounds like
Cherie was able to get it working too, though we didn't get any
clarification on why it didn't seem to work originally.


In the documentation:
"This enables you to squash and not mess up systems currently in
production that aren’t fully up-to-date yet. The recommended process is
to squash, keeping the old files, commit and release, wait until all
systems are upgraded with the new release (or if you’re a third-party
project, just ensure your users upgrade releases in order without
skipping any), and then remove the old files, commit and do a second
release."

That's right. The length of time you need to wait before removing can
vary widely. For a third-party app, it may be a full release cycle or
two (as long as you can tell your users to upgrade version-by-version).
For a project with only a few deployments, all under your control, it
may be the same day. But regardless, the squashed migration will still
be used in tests immediately, before you remove the old migrations.

Carl



--
aRkadeFR

--
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/557E9228.5080504%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Re: Running DJango with uWSGI with a user that has sudo access?

2015-06-15 Thread Avraham Serour
I think a more common case is programmer error, you may yourself harm the
system because of a bug you introduced, I once deleted a folder one level
too high (deleted the parent folder of the folder I intended to delete)
if the user only had permissions to only what it is supposed to do I would
just see an error instead of silently losing data

On Sun, Jun 14, 2015 at 10:54 PM, Carlos A. Carnero Delgado <
carloscarn...@gmail.com> wrote:

> > ... Should I try to use a user that is not a sudoer or does it not
> really matter?
>
> You should use the least privileged user you can. In the (unlikely or not)
> event of an exploit and the user can gain access to console, what can
> happen? Do you trust the system's configuration?
>
> I think that in a production settings you should go for privilege
> separation as far as possible. Besides, you could always host more than one
> service in the same box with different credentials quite nicely.
>
> HTH,
> Carlos.
>
> --
> 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/CAPjvz2%3D6SVOB7CpePNU4M-zk9q0Qh%2B2bY%2BUjpdpFBjVZKHwy3g%40mail.gmail.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/CAFWa6tL1irCV76VQLckS-B0tEH%2BMjEmDYBDN2NU8LULM-CqWXg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.