Re: How to auto fill latitude and longitude fields in Django2.0.6?

2018-06-20 Thread anthony.flury via Django users
You need access to a service (or data set) which translates addresses to 
latitude/longitude.

It will depend on your country whether this information is available and/or 
whether you need to pay for access to that service, and how that service 

Which countries will your application cover - maybe with some extra information 
someone can give you some more details.

There is nothing in django that provides this capability.

Question - why do you need latitude and longitude ?

-- 
-- Anthony Flury
email : *anthony.fl...@btinternet.com*
Twitter : *@TonyFlury * -- 
Anthony Flury
anthony.fl...@btinternet.com

  From: prateek gupta 
 To: Django users  
 Sent: Tuesday, June 19, 2018 6:45 AM
 Subject: How to auto fill latitude and longitude fields in Django2.0.6?
   
Hi All,
I have created a store address form using Django2.0.6+Mysql+Python3.6.Currently 
user has to manually fill latitude and longitude for the store address.I want 
to auto-fill both fields once user entered the address.Below is my current 
code-models.py-class Store(models.Model):
building = models.ForeignKey(Building, related_name='building', 
on_delete=models.SET_NULL, blank=True, null=True)
name = models.CharField(max_length=100)
postal_code = models.CharField(max_length=6)
address = models.TextField()
latitude = models.FloatField(validators=[MinValueValidator(-90.0), 
MaxValueValidator(90.0)])
longitude = models.FloatField(validators=[MinValueValidator(-180.0), 
MaxValueValidator(180.0)])

class Meta:
managed = False
db_table = 'store'
admin.py-class StoreAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'postal_code', 'address', 'latitude', 
 'longitude')
Can anyone please help me how to achieve this requirement?-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/56497a07-9c46-4413-9fab-db3f17298146%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2005651823.4217761.1529478393026%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with context_processor

2018-06-20 Thread Andréas Kühne
Hi Mikkel,

No - you can't loop over a dictionary that way. However - You don't need to
resort to doing that either. If you want to loop over something use a list.
Like this:

return {
  'items': [
   {'name': 'year', 'readable': 'Year', 'urlname': 'year_list' },
  {'name': 'region', 'readable': 'Region', 'urlname': 'region_list'
},
  {'name': 'location', 'readable': 'Location', 'urlname':
'location_list' }
  ]
}

Then in the template:
{% for item in Items %}
{{item.readable}}
{% endfor %}

Regards,

Andréas

2018-06-19 20:59 GMT+02:00 Mikkel Kromann :

> Thank you so much Andreas.
> This is very helpful.
>
> I wasn't able to figure that from the documentation (not sure who to
> blame, though ;)
> So I relied on various stackoverflow posts, which were quite confusing to
> say the least.
>
> Now, is there anyway I can loop over the items in the dictionary?
> In the end, I will probably query my dictionary from another model of mine.
>
> Would the { for item in items } still hold?
>
>
> cheers, Mikkel
>
> mandag den 18. juni 2018 kl. 22.55.29 UTC+2 skrev Andréas Kühne:
>
>> First of all - that is not how a context processor works.
>>
>> You are confusing template tags and context processors. A template tag is
>> one of the following:
>> https://docs.djangoproject.com/en/2.0/howto/custom-template-tags/
>>
>> It must then be registered and then included in your template. So then
>> you should put it in the templatetags module and load it into your
>> template. It should NOT be added to the OPTIONS dictionary.
>>
>> However, a context processor is called EVERYTIME a request is handled and
>> returns it's content to the template - WITHOUT the need of calling anything
>> OR adding it to your template. So in your case you would need to move the
>> context processor from the templatetags module, not load it with register,
>> and also load use {% include %} in your template. And finally don't call it.
>>
>> What happens with the context processor is that it autmatically gets
>> called and the dictionary result is added to the context of the template.
>>
>> So your context processor should look like this:
>> def GetItemDictionary(request):
>> # For now pass a hardcoded dictionary - replace with query later
>> return {
>> 'year': {'name': 'year', 'readable': 'Year', 'urlname': '
>> year_list' },
>> 'region': {'name': 'region', 'readable': 'Region', 'urlname':
>> 'region_list' },
>> 'location': {'name': 'location', 'readable': 'Location', '
>> urlname': 'location_list' },
>> }
>>
>> Without registering it or anything.
>>
>> This way you will be able to get the information in your template like
>> this:
>> {% block sidebar %}
>> 
>> {{year.readable}}
>> {{region.readable}}
>> {{location.readable}}
>> 
>> {% endblock %}
>>
>> The reason for needing to add year, region and location, is because that
>> is the way you are creating the dictionary in your context processor.
>>
>> Best regards,
>>
>> Andréas
>>
>> 2018-06-18 21:16 GMT+02:00 Mikkel Kromann :
>>
>>> Hi.
>>>
>>> Once again thanks for all your invaluable advice to me so far. Now, I'm
>>> battling context_processors.
>>> I really struggle to find a good example that can help me understand how
>>> to use them.
>>> They seem quite helpful to a lot of stuff I plan to do.
>>>
>>> I think I got the configuration in settings.py and @register right as my 
>>> tag is accepted as registered.
>>> What baffles me is whether to include "request" as argument to my context 
>>> processor GetItemDictionary()
>>> The error I get now (without declaring request as an argument) is
>>>
>>> "GetItemDictionary() takes 0 positional arguments but 1 was given"
>>>
>>>
>>> With request as argumetn to GetItemDictionary(request) I get this error:
>>>
>>> 'GetItemDictionary' did not receive value(s) for the argument(s): 'request'
>>>
>>>
>>> Should I pass request to my GetItemDictionary somewhere in my view, or
>>> is that done automagically by the template?
>>> I realise that I've probably done something wrong elsewhere, but I'm at
>>> a loss to guess where ...
>>> I suspect that the @register.simple_tag stuff I do may be the culprit as
>>> the tag may not be simple.
>>>
>>>
>>> thanks, Mikkel
>>>
>>> From project/app/templatetags/items_extra.py
>>> from django import template
>>> register = template.Library()
>>>
>>> @register.simple_tag()
>>> def GetItemDictionary():
>>> # For now pass a hardcoded dictionary - replace with query later
>>> return {
>>> 'year': {'name': 'year', 'readable': 'Year', 'urlname':
>>> 'year_list' },
>>> 'region': {'name': 'region', 'readable': 'Region', 'urlname':
>>> 'region_list' },
>>> 'location': {'name': 'location', 'readable': 'Location',
>>> 'urlname': 'location_list' },
>>> }
>>>
>>>
>>> From my settings.py
>>> TEMPLATES = [
>>> {
>>> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
>>> 'DIRS': [
>>> BASE_DIR + '/templ

Re: How to auto fill latitude and longitude fields in Django2.0.6?

2018-06-20 Thread prateek gupta
I am working in Singapore and trying to store details of different 
merchants of Singapore.
So if any merchant wants to add a new store, I am giving him this option 
build on Django.
So once he entered his store address, the lat/long fields will be auto-fill 
and location field will show the map.
The implementation part I have already covered above, you can check what 
package I am using for this functionality.

On Wednesday, June 20, 2018 at 12:37:03 PM UTC+5:30, TonyF-UK wrote:
>
> You need access to a service (or data set) which translates addresses to 
> latitude/longitude.
>
> It will depend on your country whether this information is available 
> and/or whether you need to pay for access to that service, and how that 
> service 
>
> Which countries will your application cover - maybe with some extra 
> information someone can give you some more details.
>
> There is nothing in django that provides this capability.
>
> Question - why do you need latitude and longitude ?
>
> -- 
> -- Anthony Flury
> email : *anthon...@btinternet.com *
> Twitter : *@TonyFlury *
>  
> -- 
> Anthony Flury
> anthon...@btinternet.com 
>
>
> --
> *From:* prateek gupta >
> *To:* Django users > 
> *Sent:* Tuesday, June 19, 2018 6:45 AM
> *Subject:* How to auto fill latitude and longitude fields in Django2.0.6?
>
> Hi All,
>
> I have created a store address form using Django2.0.6+Mysql+Python3.6.
> Currently user has to manually fill latitude and longitude for the store 
> address.
> I want to auto-fill both fields once user entered the address.
> Below is my current code-
> models.py-
>
> class Store(models.Model):
> building = models.ForeignKey(Building, related_name='building', 
> on_delete=models.SET_NULL, blank=True, null=True)
> name = models.CharField(max_length=100)
> postal_code = models.CharField(max_length=6)
> address = models.TextField()
> latitude = models.FloatField(validators=[MinValueValidator(-90.0), 
> MaxValueValidator(90.0)])
> longitude = models.FloatField(validators=[MinValueValidator(-180.0), 
> MaxValueValidator(180.0)])
> class Meta:
> managed = False
> db_table = 'store'
>
>
> admin.py-
>
> class StoreAdmin(admin.ModelAdmin):
> list_display = ('id', 'name', 'postal_code', 'address', 'latitude', 
>  'longitude')
>
>
> Can anyone please help me how to achieve this requirement?
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/56497a07-9c46-4413-9fab-db3f17298146%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/143e186c-2bcb-4e16-a117-4b1ae0fd4e1c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I am trying to create polls project as mentiioned in the django website

2018-06-20 Thread Sujad Syed
Hi,

I have tried my best to do this as good as possible, but i still
encountered the error.

*ERROR :*

(polls) ssyed@ssyed:~/polls/bin/mysite$ python manage.py runserver
Performing system checks...

Unhandled exception in thread started by .wrapper at 0x7f996a794598>
Traceback (most recent call last):
  File
"/home/ssyed/polls/lib/python3.6/site-packages/django/utils/autoreload.py",
line 225, in wrapper
fn(*args, **kwargs)
  File
"/home/ssyed/polls/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
line 120, in inner_run
self.check(display_num_errors=True)
  File
"/home/ssyed/polls/lib/python3.6/site-packages/django/core/management/base.py",
line 364, in check
include_deployment_checks=include_deployment_checks,
  File
"/home/ssyed/polls/lib/python3.6/site-packages/django/core/management/base.py",
line 351, in _run_checks
return checks.run_checks(**kwargs)
  File
"/home/ssyed/polls/lib/python3.6/site-packages/django/core/checks/registry.py",
line 73, in run_checks
new_errors = check(app_configs=app_configs)
  File
"/home/ssyed/polls/lib/python3.6/site-packages/django/core/checks/urls.py",
line 13, in check_url_config
return check_resolver(resolver)
  File
"/home/ssyed/polls/lib/python3.6/site-packages/django/core/checks/urls.py",
line 23, in check_resolver
return check_method()
  File
"/home/ssyed/polls/lib/python3.6/site-packages/django/urls/resolvers.py",
line 399, in check
for pattern in self.url_patterns:
  File
"/home/ssyed/polls/lib/python3.6/site-packages/django/utils/functional.py",
line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File
"/home/ssyed/polls/lib/python3.6/site-packages/django/urls/resolvers.py",
line 540, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns",
self.urlconf_module)
  File
"/home/ssyed/polls/lib/python3.6/site-packages/django/utils/functional.py",
line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File
"/home/ssyed/polls/lib/python3.6/site-packages/django/urls/resolvers.py",
line 533, in urlconf_module
return import_module(self.urlconf_name)
  File "/home/ssyed/polls/lib/python3.6/importlib/__init__.py", line 126,
in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 994, in _gcd_import
  File "", line 971, in _find_and_load
  File "", line 955, in _find_and_load_unlocked
  File "", line 665, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 219, in
_call_with_frames_removed
  File "/home/ssyed/polls/bin/mysite/mysite/urls.py", line 20, in 
path('polls/', include('polls.urls')),
NameError: name 'include' is not defined



*TREE STRUCTURE : *

(polls) ssyed@ssyed:~/polls/bin/mysite$ tree
.
├── db.sqlite3
├── manage.py
├── mysite
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   ├── settings.cpython-36.pyc
│   │   ├── urls.cpython-36.pyc
│   │   └── wsgi.cpython-36.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── polls
├── admin.py
├── apps.py
├── __init__.py
├── migrations
│   └── __init__.py
├── models.py
├── tests.py
├── urls.py
└── views.py



On Tue, Jun 19, 2018 at 8:57 PM, itsnate_b  wrote:

> Syed,
> I really suggest you follow the Django Tutorial found here: https://docs.
> djangoproject.com/en/2.0/intro/tutorial01/
>
> Go through *all* of the parts of the tutorial (there are 7 parts), line
> by line. Start with a completely new project. Jumping in and out of other
> tutorials is really not recommended (my 2 cents). I followed through all
> parts of the tutorial when I first started and found it to be a really
> great starting point. The documentation is very well written.
>
> I really can't help you if you are jumping around between different
> sites/tutorials. Start one and follow through all the way to the end.
>
> Good luck!
>
> On Tuesday, June 19, 2018 at 7:14:13 AM UTC-4, Django starter wrote:
>
>> Hi Nathan,
>>
>> I am really confused starting up with my website
>>
>> i have gone through couple of Videos and sites to start with,
>> in one of the sites, it was mentioned to make changes in urls.py and then
>> in views.py and in settings.py [Installed Apps] to have the site worked.
>>
>> unfortunately i dont see views.py
>>
>> below is the tree
>>
>> (el) ssyed@ssyed:~/el/bin$ tree
>> .
>> ├── activate
>> ├── activate.csh
>> ├── activate.fish
>> ├── activate_this.py
>> ├── chardetect
>> ├── django-admin
>> ├── django-admin.py
>> ├── easy_install
>> ├── easy_install-3.6
>> ├── elastic
>> │   ├── db.sqlite3
>> │   ├── DJango
>> │   ├── elastic
>> │   │   ├── __init__.py
>> │   │   ├── __pycache__
>> │   │   │   ├── __init__.cpython-36.pyc
>> │   │   │   ├── settings.cpython-36.pyc
>> │   │   │   ├── urls.cpython-36.pyc
>> │   │   │   └── wsgi.cpython-36.pyc
>> │   │   ├── settings.py
>> │   │   ├── urls.py
>> │   │   └── wsgi.py
>> │   └── manage.py
>>
>>
>> Could you ple

Security Check in Django

2018-06-20 Thread Jerrina Paul


Hi,

We started migrating a java project to Django .Our present code we are 
using  different filters for security. Mainly we are checking below filters

·   Session hijacking check

·   XSS attach check

·   CSRF check

·   Path manipulation check(directory traversal attack)

·   Access controller check

When I go through Django security documents ,I come across CSRF ,Session 
and XSS security. I would like to know  remaining security checks are 
already implemented in Django or we need to add our own check condition. We 
are not using Django templates for GUI .If we are adding angularJS for GUI, 
do we need to handle XSS security separately .


Regards,

Jerrina 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8ec14fa5-a9cd-4f2f-96c8-ca42036c79da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Aggregation issue

2018-06-20 Thread Gallusz Abaligeti


Hi Folks!


I have a little problem in connection with aggregation through Django's 
ORM. The sketch of my model is very simple with some custom field types 
(but those types are irrelevant in the problem):


# Fields types

class MoneyField(models.DecimalField): 
def __init__(self, *args, **kwargs): 
kwargs['null'] = True 
kwargs['blank'] = True 
kwargs['max_digits'] = 15 
kwargs['decimal_places'] = 2 
super().__init__(*args, **kwargs) 

class RevenueField(MoneyField): 
def __init__(self, *args, **kwargs): 
kwargs['validators'] = [MinValueValidator(0)] 
kwargs['null'] = True 
kwargs['blank'] = True 
super().__init__(*args, **kwargs) 

class WeakTextField(models.CharField): 
def __init__(self, *args, **kwargs): 
kwargs['max_length'] = 200 
kwargs['null'] = True 
kwargs['blank'] = True 
super().__init__(*args, **kwargs) 

class NameField(WeakTextField): 
def __init__(self, *args, **kwargs): 
kwargs['unique'] = True 
super().__init__(*args, **kwargs) 

class YearField(models.PositiveIntegerField): 
def __init__(self, *args, **kwargs): 
kwargs['validators'] = [ 
MinValueValidator(1900), 
MaxValueValidator(2100), 
] 
kwargs['null'] = True 
kwargs['blank'] = True 
super().__init__(*args, **kwargs) 

class WeakForeignKey(models.ForeignKey): 
def __init__(self, *args, **kwargs): 
kwargs['null'] = True 
kwargs['blank'] = True 
kwargs['on_delete'] = models.SET_NULL 
super().__init__(*args, **kwargs)  

# Model entities 

class Company(models.Model): 
registration_number = NameField(_('Registration number')) # custom 
field, defined above 
name = NameField(_('Name')) 
... 
.. 
. 

class Financial(models.Model): 
financial_year = YearField(_('Financial year')) 
company = WeakForeignKey(to='Company', verbose_name=_('Company')) 
revenue = RevenueField(_('Revenue')) 
... 
.. 
. 

class Meta: 
unique_together = (('financial_year', 'company'),)



My goal is to compose a query with QuerySet like this:


SELECT financial_year, SUM(revenue) 
FROM financial 
GROUP BY financial_year



As far as I could understand the ORM it should be done like this:


qs = Financial.objects.values('financial_year').annotate(Sum('revenue'))


however if i print out the SQL query it has an extra field after the Group 
By statement:


SELECT 
"data_manager_financial"."financial_year",  
CAST(SUM("data_manager_financial"."revenue") AS NUMERIC) AS 
"revenue__sum" 
FROM "data_manager_financial"  
LEFT OUTER JOIN "data_manager_company"  
ON ("data_manager_financial"."company_id" = "data_manager_company"."id")  
GROUP BY  
"data_manager_financial"."financial_year",  
*"data_manager_company"."name"*  
ORDER BY "data_manager_company"."name"  
ASC, "data_manager_financial"."financial_year" ASC



I'm afraid this problem is related with the unique constraint of the 
Financial entity. Of course the problem can be solved through raw SQL or 
through a separate entity for the financial year field but i dont like 
them. Do you have any ideas?


Thanks a lot!


Gallusz

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ff88f0f2-0081-4cba-9cc0-7f2e74e65ec8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django 1.11 Serving Large files for download ??

2018-06-20 Thread Gokul Swaminathan
How to serve large file for download. Also it should handle simultaneous 
requests. I have to serve the web application in Intranet environment. 


-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/32ed1909-da16-4254-92e6-35359db576eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Regarding an issue

2018-06-20 Thread Mayank Bhatia
hi all

I am getting an error while creating the views when i try to run the server
this Page not found (404) error is being generated. but the admin section
works fine. i am attaching the image.i have also tried making migrations
but nothing happened. kindly help to solve this asap.

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


Re: Django 1.11 Serving Large files for download ??

2018-06-20 Thread Julio Biason
Hi Gokul,

Well, since this is for intranet, you may be lucky.

For large downloads, you can put your facing server (nginx, apache) to
point directly to the media directory. For example, if your media files are
being stored on `/srv/myserver/media`, and have an URL of `/media`, you
could add a location of `/media` pointing directly to the file system (your
`/srv/myserver/media`). This way, Django won't get in the way and the whole
process of sending a large file will be the facing server problem -- and
they are better optimized for this.

The same thing goes for simultaneous requests: usually, the facing server
will launch more than one socket to the underlying service to retrieve the
information, so you end up with more "Djangos" running. One example is
that, if you use uwsgi with nginx, you can set up the number of threads
directly on uwsgi and it and nginx will take care of answering multiple
requests.

On Wed, Jun 20, 2018 at 12:07 AM, Gokul Swaminathan 
wrote:

> How to serve large file for download. Also it should handle simultaneous
> requests. I have to serve the web application in Intranet environment.
>
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/32ed1909-da16-4254-92e6-35359db576eb%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

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


Re: Regarding an issue

2018-06-20 Thread Julio Biason
Hi Mayank,

You tried to access "/"; there is no url associated with this path, so it's
a 404. The only valid URLs are `/admin` and `/music`.

If you want to see something when accessing `/`, you need to create a view
for it and associate it in your `urls.py`.

On Wed, Jun 20, 2018 at 9:39 AM, Mayank Bhatia  wrote:

> hi all
>
> I am getting an error while creating the views when i try to run the
> server this Page not found (404) error is being generated. but the admin
> section works fine. i am attaching the image.i have also tried making
> migrations but nothing happened. kindly help to solve this asap.
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CANeih2fWAJZEkD0%2BVey_Hj2cd4Cp7OEMY3qw%3DNk41eQGbi-
> vtA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

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


Re: Regarding an issue

2018-06-20 Thread MTS BOUR
Well you only have /admin and /music in urls.py you need to add / when you
configure your ulrpatterns

Le mer. 20 juin 2018 13:47, Julio Biason  a écrit :

> Hi Mayank,
>
> You tried to access "/"; there is no url associated with this path, so
> it's a 404. The only valid URLs are `/admin` and `/music`.
>
> If you want to see something when accessing `/`, you need to create a view
> for it and associate it in your `urls.py`.
>
> On Wed, Jun 20, 2018 at 9:39 AM, Mayank Bhatia 
> wrote:
>
>> hi all
>>
>> I am getting an error while creating the views when i try to run the
>> server this Page not found (404) error is being generated. but the admin
>> section works fine. i am attaching the image.i have also tried making
>> migrations but nothing happened. kindly help to solve this asap.
>>
>> --
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CANeih2fWAJZEkD0%2BVey_Hj2cd4Cp7OEMY3qw%3DNk41eQGbi-vtA%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *Julio Biason*, Sofware Engineer
> *AZION*  |  Deliver. Accelerate. Protect.
> Office: +55 51 3083 8101   |  Mobile: +55 51
> *99907 0554*
>
> --
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAEM7gE1%2BKfvFSmOzH1HZW4gQCp2PtFaLPc2_9Eq81Jh%2Bc30AsQ%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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAq3G-Gd7k7wUcwCWJKAWahpBxd%3DxyXDU8aAhCkwGsQCYaFXhA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


RE: Help with context_processor

2018-06-20 Thread Matthew Pava
Well, you can access a dictionary like a list using these:
items.keys(), template:
for k in items.keys

items.values(), template:
for v in items.values

items.items(), template:
for k, v in items.items


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Andréas Kühne
Sent: Wednesday, June 20, 2018 2:28 AM
To: django-users@googlegroups.com
Subject: Re: Help with context_processor

Hi Mikkel,

No - you can't loop over a dictionary that way. However - You don't need to 
resort to doing that either. If you want to loop over something use a list. 
Like this:

return {
  'items': [
   {'name': 'year', 'readable': 'Year', 'urlname': 'year_list' },
  {'name': 'region', 'readable': 'Region', 'urlname': 'region_list' },
  {'name': 'location', 'readable': 'Location', 'urlname': 'location_list' }
  ]
}

Then in the template:
{% for item in Items %}
{{item.readable}}
{% endfor %}

Regards,

Andréas

2018-06-19 20:59 GMT+02:00 Mikkel Kromann 
mailto:mik...@aabenhuskromann.dk>>:
Thank you so much Andreas.
This is very helpful.

I wasn't able to figure that from the documentation (not sure who to blame, 
though ;)
So I relied on various stackoverflow posts, which were quite confusing to say 
the least.

Now, is there anyway I can loop over the items in the dictionary?
In the end, I will probably query my dictionary from another model of mine.

Would the { for item in items } still hold?


cheers, Mikkel

mandag den 18. juni 2018 kl. 22.55.29 UTC+2 skrev Andréas Kühne:
First of all - that is not how a context processor works.

You are confusing template tags and context processors. A template tag is one 
of the following:
https://docs.djangoproject.com/en/2.0/howto/custom-template-tags/

It must then be registered and then included in your template. So then you 
should put it in the templatetags module and load it into your template. It 
should NOT be added to the OPTIONS dictionary.

However, a context processor is called EVERYTIME a request is handled and 
returns it's content to the template - WITHOUT the need of calling anything OR 
adding it to your template. So in your case you would need to move the context 
processor from the templatetags module, not load it with register, and also 
load use {% include %} in your template. And finally don't call it.

What happens with the context processor is that it autmatically gets called and 
the dictionary result is added to the context of the template.

So your context processor should look like this:
def GetItemDictionary(request):
# For now pass a hardcoded dictionary - replace with query later
return {
'year': {'name': 'year', 'readable': 'Year', 'urlname': 'year_list' },
'region': {'name': 'region', 'readable': 'Region', 'urlname': 
'region_list' },
'location': {'name': 'location', 'readable': 'Location', 'urlname': 
'location_list' },
}

Without registering it or anything.

This way you will be able to get the information in your template like this:
{% block sidebar %}

{{year.readable}}
{{region.readable}}
{{location.readable}}

{% endblock %}

The reason for needing to add year, region and location, is because that is the 
way you are creating the dictionary in your context processor.

Best regards,

Andréas

2018-06-18 21:16 GMT+02:00 Mikkel Kromann 
mailto:mik...@aabenhuskromann.dk>>:
Hi.

Once again thanks for all your invaluable advice to me so far. Now, I'm 
battling context_processors.
I really struggle to find a good example that can help me understand how to use 
them.
They seem quite helpful to a lot of stuff I plan to do.


I think I got the configuration in settings.py and @register right as my tag is 
accepted as registered.
What baffles me is whether to include "request" as argument to my context 
processor GetItemDictionary()
The error I get now (without declaring request as an argument) is

"GetItemDictionary() takes 0 positional arguments but 1 was given"

With request as argumetn to GetItemDictionary(request) I get this error:


'GetItemDictionary' did not receive value(s) for the argument(s): 'request'

Should I pass request to my GetItemDictionary somewhere in my view, or is that 
done automagically by the template?
I realise that I've probably done something wrong elsewhere, but I'm at a loss 
to guess where ...
I suspect that the @register.simple_tag stuff I do may be the culprit as the 
tag may not be simple.


thanks, Mikkel

>From project/app/templatetags/items_extra.py
from django import template
register = template.Library()

@register.simple_tag()
def GetItemDictionary():
# For now pass a hardcoded dictionary - replace with query later
return {
'year': {'name': 'year', 'readable': 'Year', 'urlname': 'year_list' },
'region': {'name': 'region', 'readable': 'Region', 'urlname': 
'region_list' },
'location': {'name': 'location', 'readable': 'Location', 'urlname': 
'locat

Re: Aggregation issue

2018-06-20 Thread Simon Charette
Hello Gallusz,

This is probably caused by the `Financial.Meta.ordering` that you didn't 
include in your snippet.

I assume it's currently defined as ('name', 'financial_year')?

In order to get rid of it you'll want to clear it up using an empty call to 
order_by():

Financial.objects.order_by().values('financial_year').annotate(Sum('revenue'))

FWIW there's currently an issue to stop automatically considering 
Meta.ordering when performing
GROUP'ing through values().[0][1]

Best,
Simon

[0] https://code.djangoproject.com/ticket/14357
[1] https://github.com/django/django/pull/10005

Le mercredi 20 juin 2018 07:38:19 UTC-4, Gallusz Abaligeti a écrit :
>
> Hi Folks!
>
>
> I have a little problem in connection with aggregation through Django's 
> ORM. The sketch of my model is very simple with some custom field types 
> (but those types are irrelevant in the problem):
>
>
> # Fields types
>
> class MoneyField(models.DecimalField): 
> def __init__(self, *args, **kwargs): 
> kwargs['null'] = True 
> kwargs['blank'] = True 
> kwargs['max_digits'] = 15 
> kwargs['decimal_places'] = 2 
> super().__init__(*args, **kwargs) 
>
> class RevenueField(MoneyField): 
> def __init__(self, *args, **kwargs): 
> kwargs['validators'] = [MinValueValidator(0)] 
> kwargs['null'] = True 
> kwargs['blank'] = True 
> super().__init__(*args, **kwargs) 
>
> class WeakTextField(models.CharField): 
> def __init__(self, *args, **kwargs): 
> kwargs['max_length'] = 200 
> kwargs['null'] = True 
> kwargs['blank'] = True 
> super().__init__(*args, **kwargs) 
>
> class NameField(WeakTextField): 
> def __init__(self, *args, **kwargs): 
> kwargs['unique'] = True 
> super().__init__(*args, **kwargs) 
>
> class YearField(models.PositiveIntegerField): 
> def __init__(self, *args, **kwargs): 
> kwargs['validators'] = [ 
> MinValueValidator(1900), 
> MaxValueValidator(2100), 
> ] 
> kwargs['null'] = True 
> kwargs['blank'] = True 
> super().__init__(*args, **kwargs) 
>
> class WeakForeignKey(models.ForeignKey): 
> def __init__(self, *args, **kwargs): 
> kwargs['null'] = True 
> kwargs['blank'] = True 
> kwargs['on_delete'] = models.SET_NULL 
> super().__init__(*args, **kwargs)  
>
> # Model entities 
>
> class Company(models.Model): 
> registration_number = NameField(_('Registration number')) # custom 
> field, defined above 
> name = NameField(_('Name')) 
> ... 
> .. 
> . 
>
> class Financial(models.Model): 
> financial_year = YearField(_('Financial year')) 
> company = WeakForeignKey(to='Company', verbose_name=_('Company')) 
> revenue = RevenueField(_('Revenue')) 
> ... 
> .. 
> . 
>
> class Meta: 
> unique_together = (('financial_year', 'company'),)
>
>
>
> My goal is to compose a query with QuerySet like this:
>
>
> SELECT financial_year, SUM(revenue) 
> FROM financial 
> GROUP BY financial_year
>
>
>
> As far as I could understand the ORM it should be done like this:
>
>
> qs = Financial.objects.values('financial_year').annotate(Sum('revenue'))
>
>
> however if i print out the SQL query it has an extra field after the Group 
> By statement:
>
>
> SELECT 
> "data_manager_financial"."financial_year",  
> CAST(SUM("data_manager_financial"."revenue") AS NUMERIC) AS 
> "revenue__sum" 
> FROM "data_manager_financial"  
> LEFT OUTER JOIN "data_manager_company"  
> ON ("data_manager_financial"."company_id" = "data_manager_company"."id")  
> GROUP BY  
> "data_manager_financial"."financial_year",  
> *"data_manager_company"."name"*  
> ORDER BY "data_manager_company"."name"  
> ASC, "data_manager_financial"."financial_year" ASC
>
>
>
> I'm afraid this problem is related with the unique constraint of the 
> Financial entity. Of course the problem can be solved through raw SQL or 
> through a separate entity for the financial year field but i dont like 
> them. Do you have any ideas?
>
>
> Thanks a lot!
>
>
> Gallusz
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7f545416-3425-4cc1-8476-12337d4e3419%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I am trying to create polls project as mentiioned in the django website

2018-06-20 Thread itsnate_b
Hi Syed,
Take a look at this part of the error:

 File "/home/ssyed/polls/bin/mysite/mysite/urls.py", line 20, in 
path('polls/', include('polls.urls')),
NameError: name 'include' is not defined

It appears that you have missed the addition of 'include' in your urls.py 
file. The tutorial shows the following, below - does this match your 
urls.py file contents? Note the line *from django.urls import include, path*

>From the tutorial:

The next step is to point the root URLconf at the polls.urls module. In 
mysite/urls.py, add an import for django.urls.include and insert an 
include() 
 in 
the urlpatterns list, so you have:
mysite/urls.py


from django.contrib import adminfrom django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),]



On Wednesday, June 20, 2018 at 5:12:49 AM UTC-4, Django starter wrote:
>
> Hi,
>
> I have tried my best to do this as good as possible, but i still 
> encountered the error.
>
> *ERROR :*
>
> (polls) ssyed@ssyed:~/polls/bin/mysite$ python manage.py runserver
> Performing system checks...
>
> Unhandled exception in thread started by  check_errors..wrapper at 0x7f996a794598>
> Traceback (most recent call last):
>   File 
> "/home/ssyed/polls/lib/python3.6/site-packages/django/utils/autoreload.py", 
> line 225, in wrapper
> fn(*args, **kwargs)
>   File 
> "/home/ssyed/polls/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
>  
> line 120, in inner_run
> self.check(display_num_errors=True)
>   File 
> "/home/ssyed/polls/lib/python3.6/site-packages/django/core/management/base.py",
>  
> line 364, in check
> include_deployment_checks=include_deployment_checks,
>   File 
> "/home/ssyed/polls/lib/python3.6/site-packages/django/core/management/base.py",
>  
> line 351, in _run_checks
> return checks.run_checks(**kwargs)
>   File 
> "/home/ssyed/polls/lib/python3.6/site-packages/django/core/checks/registry.py",
>  
> line 73, in run_checks
> new_errors = check(app_configs=app_configs)
>   File 
> "/home/ssyed/polls/lib/python3.6/site-packages/django/core/checks/urls.py", 
> line 13, in check_url_config
> return check_resolver(resolver)
>   File 
> "/home/ssyed/polls/lib/python3.6/site-packages/django/core/checks/urls.py", 
> line 23, in check_resolver
> return check_method()
>   File 
> "/home/ssyed/polls/lib/python3.6/site-packages/django/urls/resolvers.py", 
> line 399, in check
> for pattern in self.url_patterns:
>   File 
> "/home/ssyed/polls/lib/python3.6/site-packages/django/utils/functional.py", 
> line 36, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File 
> "/home/ssyed/polls/lib/python3.6/site-packages/django/urls/resolvers.py", 
> line 540, in url_patterns
> patterns = getattr(self.urlconf_module, "urlpatterns", 
> self.urlconf_module)
>   File 
> "/home/ssyed/polls/lib/python3.6/site-packages/django/utils/functional.py", 
> line 36, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File 
> "/home/ssyed/polls/lib/python3.6/site-packages/django/urls/resolvers.py", 
> line 533, in urlconf_module
> return import_module(self.urlconf_name)
>   File "/home/ssyed/polls/lib/python3.6/importlib/__init__.py", line 126, 
> in import_module
> return _bootstrap._gcd_import(name[level:], package, level)
>   File "", line 994, in _gcd_import
>   File "", line 971, in _find_and_load
>   File "", line 955, in 
> _find_and_load_unlocked
>   File "", line 665, in _load_unlocked
>   File "", line 678, in exec_module
>   File "", line 219, in 
> _call_with_frames_removed
>   File "/home/ssyed/polls/bin/mysite/mysite/urls.py", line 20, in 
> path('polls/', include('polls.urls')),
> NameError: name 'include' is not defined
>
>
>
> *TREE STRUCTURE : *
>
> (polls) ssyed@ssyed:~/polls/bin/mysite$ tree
> .
> ├── db.sqlite3
> ├── manage.py
> ├── mysite
> │   ├── __init__.py
> │   ├── __pycache__
> │   │   ├── __init__.cpython-36.pyc
> │   │   ├── settings.cpython-36.pyc
> │   │   ├── urls.cpython-36.pyc
> │   │   └── wsgi.cpython-36.pyc
> │   ├── settings.py
> │   ├── urls.py
> │   └── wsgi.py
> └── polls
> ├── admin.py
> ├── apps.py
> ├── __init__.py
> ├── migrations
> │   └── __init__.py
> ├── models.py
> ├── tests.py
> ├── urls.py
> └── views.py
>
>
>
> On Tue, Jun 19, 2018 at 8:57 PM, itsnate_b  > wrote:
>
>> Syed,
>> I really suggest you follow the Django Tutorial found here: 
>> https://docs.djangoproject.com/en/2.0/intro/tutorial01/
>>
>> Go through *all* of the parts of the tutorial (there are 7 parts), line 
>> by line. Start with a completely new project. Jumping in and out of other 
>> tutorials is really not recommended (my 2 cents). I followed through all 
>> parts of the tutorial when I first started and found it to be a really 
>> great starting point. The documentation is ve

Re: Forms in Bootstrap 4 Modals?

2018-06-20 Thread C. Kirby
Ok, great. I am more versed with FBVs than CBVs, but if you are doing a one 
form trial run I can figure it out.

It sounds like you are correctly rendering javascript to the client when 
they do a GET for the form, but when they do a POST (either correct or with 
validation errors) you are returning an HttpResponse, which will redirect 
to a new page. (It could be something different, but that is my first 
guess) .
It would be easiest to debug with you if I could see the code, could you 
share it here, or even better on a public code repository (github, gitlab, 
bitbucket, etc). If you can share the code I am happy to work with you on 
either tutorial.

I'm sorry, I don't have any tutorials to point to - I've been doing this 
for a long time and just pieced it together from the underlying components.

Kirby



On Tuesday, June 19, 2018 at 5:13:19 PM UTC-4, Alexander Joseph wrote:
>
> Thanks very much!
>
> I've followed a few tutorials and had mixed results - 
>
> This tutorial I got the closest with
>
> https://simpleisbetterthancomplex.com/tutorial/2016/11/15/how-to-implement-a-crud-using-ajax-and-json.html
>
> I got to the point where it says " The data was invalid. No hard refresh 
> no anything. Just this tiny part changed with the validation. This is what 
> happened:"
>
> I was able to get the form to load in the modal via ajax and the form 
> information submitted and the database updated with the new record, however 
> upon submission it would just show the ajax in a blank page rather than 
> just close the modal and show the updated table with the information. Also 
> when you submit the form and its invalid it will show the blank page with 
> ajax code rather than the validation errors in the modal. I'd much rather 
> be using CBVs though and this tutorial was for FBVs. Being such a noob it 
> would be another project altogether to turn the FBVs into CBVs and still 
> get it to work.
>
> I've tried other tutorials like this one 
> https://www.abidibo.net/blog/2015/11/18/modal-django-forms-bootstrap-4/
>
> I liked this one best because it uses CBVs and Bootstrap4, but I could 
> never even get the form to load in the modal. I checked the Javascript 
> Console and everything seemed to be fine - no missing files or errors 
> related to the modal or functioning of the modal so I'm not sure where the 
> problem was but this is my main problem right now - getting the form to 
> even show in the modal to begin with. It seems like most of these tutorials 
> use jquery/ajax to load the html form file in the modal content, is that 
> the way you did it as well?
>
> Is there a tutorial or reference you used to get it working for you? 
> If it would be easiest I can go through this tutorial again 
> https://www.abidibo.net/blog/2015/11/18/modal-django-forms-bootstrap-4/ 
> and give you any errors I get, if that tutorial looks like it will work to 
> you. In the comments it seems like theres a lot of people that had the same 
> issue I was running into with that one though.
>
> Thanks again for your help!
>
>
>
> On Tue, Jun 19, 2018 at 2:26 PM, C. Kirby > 
> wrote:
>
>> What do you seem to be having trouble with?
>>
>> -Showing the form in a modal?
>> -Dynamically loading a form based on how the modal is launched?
>> -Using the modal to handle ajax loaded/submitted forms?
>> -Generally building abootstrap4 modal?
>>
>> I have done this and am happy to help, just give me some direction in 
>> helping you
>>
>> On Tuesday, June 19, 2018 at 3:08:59 PM UTC-4, Alexander Joseph wrote:
>>>
>>> I've posted this before but havent gotten any response. If more 
>>> information is needed let me know and I'll get you anything I can.
>>>
>>> I basically want to use forms in Bootstrap 4 modals for my CRUD 
>>> operations but cant really find a good tutorial or references to work from. 
>>> I'm newer to Django still. I'm sure this is a common question/application 
>>> so theres got to be some material out there that can help a novice like me. 
>>> Has anyone had some success with implementing this? I'm using CBVs so 
>>> something that works with CBVs would be ideal. Any help, advice, or 
>>> suggestions would be much appreciated
>>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/django-users/CPspzgE33Dk/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/ac24306b-96d0-4eaa-ba23-3fedfa0a48ae%40googlegroups.com
>>  
>> 
>> .
>>
>> For 

Re: Forms in Bootstrap 4 Modals?

2018-06-20 Thread Alexander Joseph
No problem! Thanks so much for your help, I've been struggling with this
for longer than I'd like to say and havent been able to find any help.

Since I'm using a lot of mixins that I'd like to use with this view I'll
work my way through the CBV-based tutorial up until the spot where I'm
having the trouble, and then start a new github repo for this and give you
access here soon

Thanks again!

On Wed, Jun 20, 2018 at 10:28 AM, C. Kirby  wrote:

> Ok, great. I am more versed with FBVs than CBVs, but if you are doing a
> one form trial run I can figure it out.
>
> It sounds like you are correctly rendering javascript to the client when
> they do a GET for the form, but when they do a POST (either correct or with
> validation errors) you are returning an HttpResponse, which will redirect
> to a new page. (It could be something different, but that is my first
> guess) .
> It would be easiest to debug with you if I could see the code, could you
> share it here, or even better on a public code repository (github, gitlab,
> bitbucket, etc). If you can share the code I am happy to work with you on
> either tutorial.
>
> I'm sorry, I don't have any tutorials to point to - I've been doing this
> for a long time and just pieced it together from the underlying components.
>
> Kirby
>
>
>
> On Tuesday, June 19, 2018 at 5:13:19 PM UTC-4, Alexander Joseph wrote:
>>
>> Thanks very much!
>>
>> I've followed a few tutorials and had mixed results -
>>
>> This tutorial I got the closest with
>> https://simpleisbetterthancomplex.com/tutorial/2016/11/15/
>> how-to-implement-a-crud-using-ajax-and-json.html
>>
>> I got to the point where it says " The data was invalid. No hard refresh
>> no anything. Just this tiny part changed with the validation. This is what
>> happened:"
>>
>> I was able to get the form to load in the modal via ajax and the form
>> information submitted and the database updated with the new record, however
>> upon submission it would just show the ajax in a blank page rather than
>> just close the modal and show the updated table with the information. Also
>> when you submit the form and its invalid it will show the blank page with
>> ajax code rather than the validation errors in the modal. I'd much rather
>> be using CBVs though and this tutorial was for FBVs. Being such a noob it
>> would be another project altogether to turn the FBVs into CBVs and still
>> get it to work.
>>
>> I've tried other tutorials like this one
>> https://www.abidibo.net/blog/2015/11/18/modal-django-forms-bootstrap-4/
>>
>> I liked this one best because it uses CBVs and Bootstrap4, but I could
>> never even get the form to load in the modal. I checked the Javascript
>> Console and everything seemed to be fine - no missing files or errors
>> related to the modal or functioning of the modal so I'm not sure where the
>> problem was but this is my main problem right now - getting the form to
>> even show in the modal to begin with. It seems like most of these tutorials
>> use jquery/ajax to load the html form file in the modal content, is that
>> the way you did it as well?
>>
>> Is there a tutorial or reference you used to get it working for you?
>> If it would be easiest I can go through this tutorial again
>> https://www.abidibo.net/blog/2015/11/18/modal-django-forms-bootstrap-4/
>> and give you any errors I get, if that tutorial looks like it will work
>> to you. In the comments it seems like theres a lot of people that had the
>> same issue I was running into with that one though.
>>
>> Thanks again for your help!
>>
>>
>>
>> On Tue, Jun 19, 2018 at 2:26 PM, C. Kirby  wrote:
>>
>>> What do you seem to be having trouble with?
>>>
>>> -Showing the form in a modal?
>>> -Dynamically loading a form based on how the modal is launched?
>>> -Using the modal to handle ajax loaded/submitted forms?
>>> -Generally building abootstrap4 modal?
>>>
>>> I have done this and am happy to help, just give me some direction in
>>> helping you
>>>
>>> On Tuesday, June 19, 2018 at 3:08:59 PM UTC-4, Alexander Joseph wrote:

 I've posted this before but havent gotten any response. If more
 information is needed let me know and I'll get you anything I can.

 I basically want to use forms in Bootstrap 4 modals for my CRUD
 operations but cant really find a good tutorial or references to work from.
 I'm newer to Django still. I'm sure this is a common question/application
 so theres got to be some material out there that can help a novice like me.
 Has anyone had some success with implementing this? I'm using CBVs so
 something that works with CBVs would be ideal. Any help, advice, or
 suggestions would be much appreciated

>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>>> pic/django-users/CPspzgE33Dk/unsubscribe.
>>> To unsubscribe from this group and all its topi

python inspectdb got "The error was: function unnest(smallint[]) does not exist"

2018-06-20 Thread weiwei . hsieh
I use Amazon Redshift database and Django 2.0.6.   My redshift database 
settings is as below:

DATABASES = {

'default': {

'NAME': 'my_db_name',

'ENGINE': 'django.db.backends.postgresql_psycopg2',

'USER': 'my_username',

'PASSWORD': 'my_password',

'HOST': 'my_hostname',

'PORT': 5439,

},

}


When I run "python3 manage.py inspectdb", I got below error messages:


# Unable to inspect table 'eld_messages'

# The error was: function unnest(smallint[]) does not exist

HINT:  No function matches the given name and argument types. You may need 
to add explicit type casts.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c80569a6-2beb-4cbd-ad71-ed8470c645c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with context_processor

2018-06-20 Thread Andréas Kühne
Hi Matthew,

That's true, You would then be able to get the dictionary values once more.
Hadn't thought of that. Good point! Thanks :-)

Regards,

Andréas

2018-06-20 15:55 GMT+02:00 Matthew Pava :

> Well, you can access a dictionary like a list using these:
>
> items.keys(), template:
>
> for k in items.keys
>
>
>
> items.values(), template:
>
> for v in items.values
>
>
>
> items.items(), template:
>
> for k, v in items.items
>
>
>
>
>
> *From:* django-users@googlegroups.com [mailto:django-users@
> googlegroups.com] *On Behalf Of *Andréas Kühne
> *Sent:* Wednesday, June 20, 2018 2:28 AM
> *To:* django-users@googlegroups.com
> *Subject:* Re: Help with context_processor
>
>
>
> Hi Mikkel,
>
>
>
> No - you can't loop over a dictionary that way. However - You don't need
> to resort to doing that either. If you want to loop over something use a
> list. Like this:
>
>
>
> return {
>
>   'items': [
>
>{'name': 'year', 'readable': 'Year', 'urlname': 'year_list' },
>
>   {'name': 'region', 'readable': 'Region', 'urlname':
> 'region_list' },
>
>   {'name': 'location', 'readable': 'Location', 'urlname':
> 'location_list' }
>
>   ]
>
> }
>
>
>
> Then in the template:
>
> {% for item in Items %}
> {{item.readable}}
> {% endfor %}
>
>
> Regards,
>
>
>
> Andréas
>
>
>
> 2018-06-19 20:59 GMT+02:00 Mikkel Kromann :
>
> Thank you so much Andreas.
>
> This is very helpful.
>
>
>
> I wasn't able to figure that from the documentation (not sure who to
> blame, though ;)
>
> So I relied on various stackoverflow posts, which were quite confusing to
> say the least.
>
>
>
> Now, is there anyway I can loop over the items in the dictionary?
>
> In the end, I will probably query my dictionary from another model of mine.
>
>
>
> Would the { for item in items } still hold?
>
>
>
>
>
> cheers, Mikkel
>
>
>
> mandag den 18. juni 2018 kl. 22.55.29 UTC+2 skrev Andréas Kühne:
>
> First of all - that is not how a context processor works.
>
>
>
> You are confusing template tags and context processors. A template tag is
> one of the following:
>
> https://docs.djangoproject.com/en/2.0/howto/custom-template-tags/
>
>
>
> It must then be registered and then included in your template. So then you
> should put it in the templatetags module and load it into your template. It
> should NOT be added to the OPTIONS dictionary.
>
>
>
> However, a context processor is called EVERYTIME a request is handled and
> returns it's content to the template - WITHOUT the need of calling anything
> OR adding it to your template. So in your case you would need to move the
> context processor from the templatetags module, not load it with register,
> and also load use {% include %} in your template. And finally don't call it.
>
>
>
> What happens with the context processor is that it autmatically gets
> called and the dictionary result is added to the context of the template.
>
>
>
> So your context processor should look like this:
>
> def GetItemDictionary(request):
> # For now pass a hardcoded dictionary - replace with query later
> return {
> 'year': {'name': 'year', 'readable': 'Year', 'urlname':
> 'year_list' },
> 'region': {'name': 'region', 'readable': 'Region', 'urlname':
> 'region_list' },
> 'location': {'name': 'location', 'readable': 'Location', 'urlname'
> : 'location_list' },
> }
>
>
>
> Without registering it or anything.
>
>
>
> This way you will be able to get the information in your template like
> this:
>
> {% block sidebar %}
> 
>
> {{year.readable}}
>
> {{region.readable}}
>
> {{location.readable}}
> 
> {% endblock %}
>
>
>
> The reason for needing to add year, region and location, is because that
> is the way you are creating the dictionary in your context processor.
>
>
> Best regards,
>
>
>
> Andréas
>
>
>
> 2018-06-18 21:16 GMT+02:00 Mikkel Kromann :
>
> Hi.
>
>
>
> Once again thanks for all your invaluable advice to me so far. Now, I'm
> battling context_processors.
>
> I really struggle to find a good example that can help me understand how
> to use them.
>
> They seem quite helpful to a lot of stuff I plan to do.
>
>
>
> I think I got the configuration in settings.py and @register right as my tag 
> is accepted as registered.
> What baffles me is whether to include "request" as argument to my context 
> processor GetItemDictionary()
> The error I get now (without declaring request as an argument) is
>
> "GetItemDictionary() takes 0 positional arguments but 1 was given"
>
>
>
> With request as argumetn to GetItemDictionary(request) I get this error:
>
>
>
> 'GetItemDictionary' did not receive value(s) for the argument(s): 'request'
>
>
>
> Should I pass request to my GetItemDictionary somewhere in my view, or is
> that done automagically by the template?
>
> I realise that I've probably done something wrong elsewhere, but I'm at a
> loss to guess where ...
>
> I suspect that the @register.simple_tag stuff I do may be the cul

Re: Help with context_processor

2018-06-20 Thread Mikkel Kromann
Thank you both. 
Clearly, I also missed some important points about dictionaries.
Mistakes are good teachers, but it surely helps having competent people on 
a mailing list :)

I'll sum up the simple solution to context processors that worked for me, 
if somebody would find it useful some day.

Basically in any of your .py files you can put a definition taking 
'request' as argument and returning a dictionary.
Recommended file is /contextprocessor.py (my  is named items) 
def GetItemDictionary(request):
return {
 'itemDictionary': [
{'name': 'region', 'readable': 'Region', 'urlname': 
'region_list' }, 
{'name': 'location', 'readable': 'Location', 'urlname': 
'location_list' },
]
}



This will allow you to iterate over the dictionary 'itemDictionary' in all 
your templates, e.g. in template.html
{% for item in itemDictionary %}
{{ item.readable }}
{% endfor %}


To ensure that Django passes the itemDictionary dict to the template, you 
will need to register it in settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
BASE_DIR + '/templates/',
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'items.contextprocessor.GetItemDictionary',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

And that's about it. Thanks again to Matthew and Andréas for helping me out 
here.


cheers, Mikkel



onsdag den 20. juni 2018 kl. 20.34.50 UTC+2 skrev Andréas Kühne:
>
> Hi Matthew,
>
> That's true, You would then be able to get the dictionary values once 
> more. Hadn't thought of that. Good point! Thanks :-)
>
> Regards,
>
> Andréas
>
> 2018-06-20 15:55 GMT+02:00 Matthew Pava >:
>
>> Well, you can access a dictionary like a list using these:
>>
>> items.keys(), template:
>>
>> for k in items.keys
>>
>>  
>>
>> items.values(), template:
>>
>> for v in items.values
>>
>>  
>>
>> items.items(), template:
>>
>> for k, v in items.items
>>
>>  
>>
>>  
>>
>> *From:* django...@googlegroups.com  [mailto:
>> django...@googlegroups.com ] *On Behalf Of *Andréas Kühne
>> *Sent:* Wednesday, June 20, 2018 2:28 AM
>> *To:* django...@googlegroups.com 
>> *Subject:* Re: Help with context_processor
>>
>>  
>>
>> Hi Mikkel,
>>
>>  
>>
>> No - you can't loop over a dictionary that way. However - You don't need 
>> to resort to doing that either. If you want to loop over something use a 
>> list. Like this:
>>
>>  
>>
>> return {
>>
>>   'items': [
>>
>>{'name': 'year', 'readable': 'Year', 'urlname': 'year_list' },
>>
>>   {'name': 'region', 'readable': 'Region', 'urlname': 
>> 'region_list' },
>>
>>   {'name': 'location', 'readable': 'Location', 'urlname': 
>> 'location_list' }
>>
>>   ]
>>
>> }
>>
>>  
>>
>> Then in the template:
>>
>> {% for item in Items %}
>> {{item.readable}}
>> {% endfor %}
>>
>>
>> Regards,
>>
>>  
>>
>> Andréas
>>
>>  
>>
>> 2018-06-19 20:59 GMT+02:00 Mikkel Kromann > >:
>>
>> Thank you so much Andreas.
>>
>> This is very helpful.
>>
>>  
>>
>> I wasn't able to figure that from the documentation (not sure who to 
>> blame, though ;)
>>
>> So I relied on various stackoverflow posts, which were quite confusing to 
>> say the least.
>>
>>  
>>
>> Now, is there anyway I can loop over the items in the dictionary?
>>
>> In the end, I will probably query my dictionary from another model of 
>> mine.
>>
>>  
>>
>> Would the { for item in items } still hold? 
>>
>>  
>>
>>  
>>
>> cheers, Mikkel
>>
>>  
>>
>> mandag den 18. juni 2018 kl. 22.55.29 UTC+2 skrev Andréas Kühne:
>>
>> First of all - that is not how a context processor works.
>>
>>  
>>
>> You are confusing template tags and context processors. A template tag is 
>> one of the following:
>>
>> https://docs.djangoproject.com/en/2.0/howto/custom-template-tags/
>>
>>  
>>
>> It must then be registered and then included in your template. So then 
>> you should put it in the templatetags module and load it into your 
>> template. It should NOT be added to the OPTIONS dictionary.
>>
>>  
>>
>> However, a context processor is called EVERYTIME a request is handled and 
>> returns it's content to the template - WITHOUT the need of calling anything 
>> OR adding it to your template. So in your case you would need to move the 
>> context processor from the templatetags module, not load it with register, 
>> and also load use {% include %} in your template. And finally don't call it.
>>
>>  
>>
>> What happens with the context processor is that it autmatically gets 
>> called and the dictionary result is added to the context of the template.
>>
>>  
>>
>> So your context processor shou

Re: Forms in Bootstrap 4 Modals?

2018-06-20 Thread Alexander Joseph
Actually on second thought, since this is a private github repo and theres 
a lot of stuff in there i wouldnt want to make public, copying it/cleaning 
it up to make it a public repo would be a bit of an ordeal so I'll just 
post my code here.

So going through this tutorial - 
https://www.abidibo.net/blog/2015/11/18/modal-django-forms-bootstrap-4/

below is my url

url(r'^gaas-wafer-designs/create/$', gaas_wafer_designs.
GaasWaferDesignCreateView.as_view(), name='gaas_wafer_design_create'),


below is my view

class GaasWaferDesignCreateView(LoginRequiredMixin, CreateView):
fields = ("design_ui", "emitting", "contact_location", "optical_power", 
"design_date", "designer", "design_document", "designer_ui", "in_trash", 
"inactive_date", "notes")
model = GaasWaferDesign
template_name = 
'engineering/gaas_wafer_designs/gaas_wafer_design_form_inner.html'

def form_valid(self, form):
self.object = form.save()
return render(self.request, 
'engineering/gaas_wafer_designs/create_success.html', 
{'gaas_wafer_designs': self.object})


and below is my gaas_wafer_design_list.html (the template with the modal 
frame and modal button along with the jquery to handle the ajax) -

{% extends "pages/list_template.html" %}{% load static from staticfiles %}
{% load widget_tweaks %}

{% block title %}GaAs Wafer Design List{% endblock %}
{% block list_title %}GaAs Wafer Designs{% endblock %}
{% block list_title_2 %}Design Inventory{% endblock %}

{% block extra_js%}
https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js";>
http://malsup.github.com/jquery.form.js";>
{% endblock %}

{% block buttons %}
  
  
  

View


Recycling Bin

  
  
  Click here to show the modal
  
{% endblock %}

{% block table %}
  
  
  
  Wafer Design UI
  
  
  Emitting Type
  
  
  Contact Location
  
  
  Optical Power
  
  
  Design Date
  
  
  Designer
  
  
  Designer UI
  
  
  Created At
  
  
  
  
  
  
  Wafer Design UI
  
  
  Emitting Type
  
  
  Contact Location
  
  
  Optical Power
  
  
  Design Date
  
  
  Designer
  
  
  Designer UI
  
  
  Created At
  
  
  
  
  {% for gaas_wafer_design in gaas_wafer_designs %}
  
  {{ gaas_wafer_design.design_ui }}
  {{ gaas_wafer_design.get_emitting_display }}
  {{ gaas_wafer_design.contact_location }}
  {{ gaas_wafer_design.optical_power }}
  {{ gaas_wafer_design.design_date|date:"m/d/y" }}
  {{ gaas_wafer_design.designer }}
  {{ gaas_wafer_design.designer_ui }}
  {{ gaas_wafer_design.created_at }}
  
  {% endfor %}
  

  
$('#modal').on('show.bs.modal', function (event) {
var modal = $(this)
$.ajax({
url: "{% url 'engineering:gaas_wafer_design_create' %}",
context: document.body
}).done(function(response) {
modal.html(response);
});
})
  
{% endblock %}
{% block modal %}

{% endblock %}


below is my gaas_wafer_design_form.html (the modal content/form) - 

{% load i18n widget_tweaks %}

{% csrf_token %}



×
Close

Add News


Test


Close






var form_options = { target: '#modal', success: function(response) {} };
$('#gaas-create').ajaxForm(form_options);



below is my create_success.html





×
Test

Test


Succesfully created!

 


// close the modal after 3 seconds
setTimeout(function() {
$('#modal').modal('hide');
}, 3000);



The first problem I'm running into with this is when I click on the link to 
show the modal the screen darkens from the modal fade but no modal shows up 
at all. I checked the javascript console (see below) and it doesnt look 
like anything is missing. I'm thinking its probably somewhere in the ajax 
thats messed up


Thanks again





On Wednesday, June 20, 2018 at 10:28:40 AM UTC-6, C. Kirby wrote:
>
> Ok, great. I am more versed with FBVs than CBVs, but if you are doing a 
> one form trial run I can figure it out.
>
> It

Re: Aggregation issue

2018-06-20 Thread Gallusz Abaligeti
Hi!

Yes exactly, the ordering meta was

ordering = ('company', 'financial_year',)

and addig order_by('financial_year') to the QuerySet solved the problem (
https://stackoverflow.com/questions/50944536/django-aggregation-issue)

Thanks,
Gallusz

2018. június 20., szerda 16:23:40 UTC+2 időpontban Simon Charette a 
következőt írta:
>
> Hello Gallusz,
>
> This is probably caused by the `Financial.Meta.ordering` that you didn't 
> include in your snippet.
>
> I assume it's currently defined as ('name', 'financial_year')?
>
> In order to get rid of it you'll want to clear it up using an empty call 
> to order_by():
>
>
> Financial.objects.order_by().values('financial_year').annotate(Sum('revenue'))
>
> FWIW there's currently an issue to stop automatically considering 
> Meta.ordering when performing
> GROUP'ing through values().[0][1]
>
> Best,
> Simon
>
> [0] https://code.djangoproject.com/ticket/14357
> [1] https://github.com/django/django/pull/10005
>
> Le mercredi 20 juin 2018 07:38:19 UTC-4, Gallusz Abaligeti a écrit :
>>
>> Hi Folks!
>>
>>
>> I have a little problem in connection with aggregation through Django's 
>> ORM. The sketch of my model is very simple with some custom field types 
>> (but those types are irrelevant in the problem):
>>
>>
>> # Fields types
>>
>> class MoneyField(models.DecimalField): 
>> def __init__(self, *args, **kwargs): 
>> kwargs['null'] = True 
>> kwargs['blank'] = True 
>> kwargs['max_digits'] = 15 
>> kwargs['decimal_places'] = 2 
>> super().__init__(*args, **kwargs) 
>>
>> class RevenueField(MoneyField): 
>> def __init__(self, *args, **kwargs): 
>> kwargs['validators'] = [MinValueValidator(0)] 
>> kwargs['null'] = True 
>> kwargs['blank'] = True 
>> super().__init__(*args, **kwargs) 
>>
>> class WeakTextField(models.CharField): 
>> def __init__(self, *args, **kwargs): 
>> kwargs['max_length'] = 200 
>> kwargs['null'] = True 
>> kwargs['blank'] = True 
>> super().__init__(*args, **kwargs) 
>>
>> class NameField(WeakTextField): 
>> def __init__(self, *args, **kwargs): 
>> kwargs['unique'] = True 
>> super().__init__(*args, **kwargs) 
>>
>> class YearField(models.PositiveIntegerField): 
>> def __init__(self, *args, **kwargs): 
>> kwargs['validators'] = [ 
>> MinValueValidator(1900), 
>> MaxValueValidator(2100), 
>> ] 
>> kwargs['null'] = True 
>> kwargs['blank'] = True 
>> super().__init__(*args, **kwargs) 
>>
>> class WeakForeignKey(models.ForeignKey): 
>> def __init__(self, *args, **kwargs): 
>> kwargs['null'] = True 
>> kwargs['blank'] = True 
>> kwargs['on_delete'] = models.SET_NULL 
>> super().__init__(*args, **kwargs)  
>>
>> # Model entities 
>>
>> class Company(models.Model): 
>> registration_number = NameField(_('Registration number')) # custom 
>> field, defined above 
>> name = NameField(_('Name')) 
>> ... 
>> .. 
>> . 
>>
>> class Financial(models.Model): 
>> financial_year = YearField(_('Financial year')) 
>> company = WeakForeignKey(to='Company', verbose_name=_('Company')) 
>> revenue = RevenueField(_('Revenue')) 
>> ... 
>> .. 
>> . 
>>
>> class Meta: 
>> unique_together = (('financial_year', 'company'),)
>>
>>
>>
>> My goal is to compose a query with QuerySet like this:
>>
>>
>> SELECT financial_year, SUM(revenue) 
>> FROM financial 
>> GROUP BY financial_year
>>
>>
>>
>> As far as I could understand the ORM it should be done like this:
>>
>>
>> qs = Financial.objects.values('financial_year').annotate(Sum('revenue'))
>>
>>
>> however if i print out the SQL query it has an extra field after the 
>> Group By statement:
>>
>>
>> SELECT 
>> "data_manager_financial"."financial_year",  
>> CAST(SUM("data_manager_financial"."revenue") AS NUMERIC) AS 
>> "revenue__sum" 
>> FROM "data_manager_financial"  
>> LEFT OUTER JOIN "data_manager_company"  
>> ON ("data_manager_financial"."company_id" = "data_manager_company"."id") 
>>  
>> GROUP BY  
>> "data_manager_financial"."financial_year",  
>> *"data_manager_company"."name"*  
>> ORDER BY "data_manager_company"."name"  
>> ASC, "data_manager_financial"."financial_year" ASC
>>
>>
>>
>> I'm afraid this problem is related with the unique constraint of the 
>> Financial entity. Of course the problem can be solved through raw SQL or 
>> through a separate entity for the financial year field but i dont like 
>> them. Do you have any ideas?
>>
>>
>> Thanks a lot!
>>
>>
>> Gallusz
>>
>

-- 
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 https://groups.google.co

Re: Django 1.11 Serving Large files for download ??

2018-06-20 Thread Gokul Swaminathan
Hi Julio, 

   Thank you for that. You mean to say that we have to leave it web 
server rather then Django. But the files have to be authenticated based on 
the request. When a person 
requests for a file only his respective file has to be provided for 
download.

With a bit of googling i checked FileResponse can be used from if it has be 
handled by Django or We can use Apache2 Xsend-file

Apache2 xsendfile is what you will be suggesting for this. Or does it has 
be handled in any other way. 
On Wednesday, 20 June 2018 18:12:36 UTC+5:30, Julio Biason wrote:
>
> Hi Gokul,
>
> Well, since this is for intranet, you may be lucky.
>
> For large downloads, you can put your facing server (nginx, apache) to 
> point directly to the media directory. For example, if your media files are 
> being stored on `/srv/myserver/media`, and have an URL of `/media`, you 
> could add a location of `/media` pointing directly to the file system (your 
> `/srv/myserver/media`). This way, Django won't get in the way and the whole 
> process of sending a large file will be the facing server problem -- and 
> they are better optimized for this.
>
> The same thing goes for simultaneous requests: usually, the facing server 
> will launch more than one socket to the underlying service to retrieve the 
> information, so you end up with more "Djangos" running. One example is 
> that, if you use uwsgi with nginx, you can set up the number of threads 
> directly on uwsgi and it and nginx will take care of answering multiple 
> requests.
>
> On Wed, Jun 20, 2018 at 12:07 AM, Gokul Swaminathan  > wrote:
>
>> How to serve large file for download. Also it should handle simultaneous 
>> requests. I have to serve the web application in Intranet environment. 
>>
>>
>> -- 
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/32ed1909-da16-4254-92e6-35359db576eb%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> *Julio Biason*, Sofware Engineer
> *AZION*  |  Deliver. Accelerate. Protect.
> Office: +55 51 3083 8101  |  Mobile: +55 51 *99907 0554*
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/39c51e7d-466d-4b70-b316-8a55883e5148%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to fetch latitude and longitude from location field and save them separately in db (Django 2.0.6+Python3.6)?

2018-06-20 Thread prateek gupta
Hi All,

I have created a model in Django 2.0.6+Python 3.6 which maps to a table in 
Database i.e. store table
This store table has columns- id, name, address, location, latitude, 
longitude.

Currently user don't have to manually fill the location field, it is filled 
with latitude,longitude based on the address entered. For this purpose I am 
using following package in Django- django-location-field 


I need to fetch the values of latitude/longitude from this location field 
and save into respective latitude and longitude columns in db.
Currently in DB only location field is saved with latitude,longitude values.

How can I achieve this?

My Code is as below-

models.py:
from location_field.models.plain import PlainLocationField
class Store(OwnedModel):
   name = models.CharField(max_length=100)
   address = models.TextField(default='Mumbai')
   location = PlainLocationField(based_fields=['address'], zoom=7, null=True
)
class Meta:
   managed = False
   db_table = 'store'

admin.py:
class StoreAdmin(admin.ModelAdmin):
   list_display = ('id', 'name', 'address')


-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c2dc13d9-3c0b-4bb0-845e-82f05f8d7ad6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.