NoReverseMatch error raise when adding a new entry in django admin

2018-02-11 Thread Weifeng Pan
I got this wired issue. who can help.

Python 3.6
Django Latest 2.0.2

following are stack trace---
Internal Server Error: /admin/nmm_tokenservice/userprofile/add/ Traceback 
(most recent call last): File 
"C:\Python36\lib\site-packages\django\core\handlers\exception.py", line 35, 
in inner response = get_response(request) File 
"C:\Python36\lib\site-packages\django\core\handlers\base.py", line 128, in 
_get_response response = self.process_exception_by_middleware(e, request) 
File "C:\Python36\lib\site-packages\django\core\handlers\base.py", line 
126, in _get_response response = wrapped_callback(request, *callback_args, 
**callback_kwargs) File 
"C:\Python36\lib\site-packages\django\contrib\admin\options.py", line 574, 
in wrapper return self.admin_site.admin_view(view)(*args, **kwargs) File 
"C:\Python36\lib\site-packages\django\utils\decorators.py", line 142, in 
_wrapped_view response = view_func(request, *args, **kwargs) File 
"C:\Python36\lib\site-packages\django\views\decorators\cache.py", line 44, 
in _wrapped_view_func response = view_func(request, *args, **kwargs) File 
"C:\Python36\lib\site-packages\django\contrib\admin\sites.py", line 223, in 
inner return view(request, *args, **kwargs) File 
"C:\Python36\lib\site-packages\django\contrib\admin\options.py", line 1553, 
in add_view return self.changeform_view(request, None, form_url, 
extra_context) File 
"C:\Python36\lib\site-packages\django\utils\decorators.py", line 62, in 
_wrapper return bound_func(*args, **kwargs) File 
"C:\Python36\lib\site-packages\django\utils\decorators.py", line 142, in 
_wrapped_view response = view_func(request, *args, **kwargs) File 
"C:\Python36\lib\site-packages\django\utils\decorators.py", line 58, in 
bound_func return func.__get__(self, type(self))(*args2, **kwargs2) File 
"C:\Python36\lib\site-packages\django\contrib\admin\options.py", line 1450, 
in changeform_view return self._changeform_view(request, object_id, 
form_url, extra_context) File 
"C:\Python36\lib\site-packages\django\contrib\admin\options.py", line 1495, 
in _changeform_view return self.response_add(request, new_object) File 
"C:\Python36\lib\site-packages\django\contrib\admin\options.py", line 1098, 
in response_add current_app=self.admin_site.name, File 
"C:\Python36\lib\site-packages\django\urls\base.py", line 88, in reverse 
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, 
**kwargs)) File "C:\Python36\lib\site-packages\django\urls\resolvers.py", 
line 632, in _reverse_with_prefix raise NoReverseMatch(msg) 
django.urls.exceptions.NoReverseMatch: Reverse for 
'nmm_tokenservice_userprofile_change' with arguments '('',)' not found. 1 
pattern(s) tried: 
['admin/nmm_tokenservice\\/userprofile\\/(?P.+)\\/change\\/$']

* here is my model---*
class UserProfile(models.Model):
#base information
user = models.OneToOneField(User, on_delete=models.deletion.CASCADE, 
verbose_name='系统账户', related_name='profile')
uid = UIDField(verbose_name='用户ID', primary_key=True, editable=False, null=
False, blank=False)
imuid = UIDField(verbose_name='IM用户ID', editable=False, null=True, blank=
True)
nickname = models.CharField(verbose_name='昵称', max_length=20, null=True, 
blank=True, db_index=True)
tel = models.CharField(verbose_name='手机号码', max_length=20, null=True, blank=
False)
#status and level
status = models.CharField(verbose_name='状态', max_length=20, null=False, 
blank=False, default=USER_STATUS[0][0], choices=USER_STATUS)
level = models.PositiveIntegerField(verbose_name='级别', null=False, blank=
False, default=1, db_index=True)
#org information
city = CityCodeField(verbose_name='城市', null=True, blank=False)
org = CodeField(verbose_name='学校或组织机构代码', null=True, blank=True, db_index=
True)
textbookcode = LabelCodeField(verbose_name='教材(标签代码)', help_text='请填写标签代码', 
null=True, blank=True, db_index=True)
gradecode = LabelCodeField(verbose_name='年级/级别(标签代码)', help_text='请填写标签代码', 
null=True, blank=True, db_index=True)
#role
role = UserRoleField(verbose_name='角色', null=False, blank=False, 
choices=UserRole_CHOICES, 
default=UserRole.user.name)
### teacher specific attributes ###
synopsis = models.TextField(verbose_name='个人简介', max_length=500, null=True, 
blank=True)
workhistory = models.TextField(verbose_name='工作经历', max_length=500, null=
True, blank=True)
cert = models.TextField(verbose_name='荣誉证书', max_length=500, null=True, 
blank=True)
labels = models.CharField(verbose_name='个人标签', max_length=100, null=True, 
blank=True)
scope = models.CharField(verbose_name='出题范围', help_text='老师的出题范围,仅对老师角色有效', 
max_length=100, null=True, blank=True)
title = models.PositiveIntegerField(verbose_name='头衔级别', null=False, blank=
False, default=1, db_index=True)
### promotion and relation ###
promotioncode = PromotionCodeField(verbose_name='推荐码', help_text=
'用于推荐其他用户或者老师', null=True, blank=True)
broker_promote = UIDField(verbose_name='推荐者用户ID', null=True, blank=True, 
db_index=True)
broker_firstserve = 

Re: loading script deployment

2018-02-11 Thread Leif
Thank you, Jani,
I will try.
Best,
Leif

On Saturday, February 10, 2018 at 10:14:29 AM UTC-5, Leif wrote:
>
> Dear Django,
>
> Sorry if this question has been answered. I have a Django based web 
> application and I just developed a loading script to upload data to 
> database using django model. The code is located under management/commands. 
> Here is the commands to run the script:
>
> $source ./appenv/bin/activate appenv
> (appenv)$python manage.py load_data data_file.csv
>
> I would like to deploy this script to my client. I don't want to send the 
> entire code of web application. How do I do it? 
>
> Thank you in advance for your help.
>
> Best,
>
> Leif
>

-- 
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/55817374-92fb-4a8e-81ff-d239158793c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing Channels 2.0 consumers - problem with routing

2018-02-11 Thread Andrew Godwin
Hi,

This is a known issue with the Redis backend -
https://github.com/django/channels/issues/859

I am looking at it today.

Andrew

On Sun, Feb 11, 2018 at 8:54 AM, Azamat Galimzhanov 
wrote:

> After fixing this issue, here is the updated consumer:
>
>
> from functools import lru_cache
>
> from asgiref.sync import AsyncToSync
> from channels.generic.websocket import WebsocketConsumer
>
>
> class AuctionConsumer(WebsocketConsumer):
> @property
> @lru_cache(maxsize=None)
> def group_name(self):
> path = self.scope['path']
> auction_id = path[len('auctions/'):-1]
> return 'auction_{}'.format(auction_id)
>
> def connect(self):
> AsyncToSync(self.channel_layer.group_add)(self.group_name, 
> self.channel_name)
> self.accept()
>
> def disconnect(self, close_code):
> AsyncToSync(self.channel_layer.group_discard)(self.group_name, 
> self.channel_name)
>
> def receive(self, text_data):
> AsyncToSync(self.channel_layer.group_send)(
> self.group_name,
> {
> 'type': 'auction.bid',
> 'text': text_data,
> },
> )
>
> def auction_bid(self, event):
> self.send(text_data=event['text'])
>
>
>  some of my other tests seem to have influence test_consumers, so I set up
> a simplified test case, here it is:
>
> from channels.layers import get_channel_layer
> from asgiref.sync import AsyncToSync
>
> import pytest
> from channels.testing import WebsocketCommunicator
> from auctions.consumers import AuctionConsumer
>
>
> def test_A():
> channel_layer = get_channel_layer()
> AsyncToSync(channel_layer.group_send)(
> 'auction_1',
> {
> 'type': 'auction.bid',
> 'text': '1'
> }
> )
>
>
> @pytest.mark.asyncio
> async def test_B():
> communicator = WebsocketCommunicator(AuctionConsumer, 'auctions/1/')
> connected, subprotocol = await communicator.connect()
> assert connected
> # Test sending text
> await communicator.send_to(text_data='1')
> response = await communicator.receive_from()
> assert response == '1'
> # Close
> await communicator.disconnect()
>
>
> And individually they pass:
>
>  !  ◰³ django_root-FXsg3jFU  /m/k/D/d/auction   41/bidding_websockets
> *…  django_root  pytest -v -s auctions/tests/test_test.py::test_A
>   5.8s  Sun 11 Feb 2018 10:46:12 PM +06
> 
> === test session starts
> 
> ===
> platform linux -- Python 3.6.3, pytest-3.4.0, py-1.5.2, pluggy-0.6.0 --
> /home/khazidhea/.local/share/virtualenvs/django_root-
> FXsg3jFU/bin/python3.6m
> cachedir: .pytest_cache
> Django settings: core.settings (from ini file)
> rootdir: /media/khazidhea/Data/dev/auction/django_root, inifile: setup.cfg
> plugins: mock-1.6.3, flake8-0.9.1, django-3.1.2, cov-2.5.1, asyncio-0.8.0,
> celery-4.1.0
> collected 1 item
>
>
>
> auctions/tests/test_test.py::test_A PASSED
>
> 
>  1 passed in 0.07 seconds
> 
> =
>  ◰³ django_root-FXsg3jFU  /m/k/D/d/auction   41/bidding_websockets *… 
> django_root  pytest -v -s auctions/tests/test_test.py::test_B
>   4053ms  Sun 11 Feb 2018 10:46:20 PM +06
> 
> === test session starts
> 
> ===
> platform linux -- Python 3.6.3, pytest-3.4.0, py-1.5.2, pluggy-0.6.0 --
> /home/khazidhea/.local/share/virtualenvs/django_root-
> FXsg3jFU/bin/python3.6m
> cachedir: .pytest_cache
> Django settings: core.settings (from ini file)
> rootdir: /media/khazidhea/Data/dev/auction/django_root, inifile: setup.cfg
> plugins: mock-1.6.3, flake8-0.9.1, django-3.1.2, cov-2.5.1, asyncio-0.8.0,
> celery-4.1.0
> collected 1 item
>
>
>
> auctions/tests/test_test.py::test_B PASSED
>
> 
>  1 passed in 0.09 seconds
> 
> =
> Task was destroyed but it is pending!
> task:  /home/khazidhea/.local/share/virtualenvs/django_root-
> FXsg3jFU/lib/python3.6/site-packages/aioredis/connection.py:175>
> wait_for= 0x7f19b9b6bbe8>()]> cb=[Future.set_result()]>
>
>
>
>
> But when I run both (I think specifically when B is run after A) I get a
> huge traceback with this in the end:
>
> def _check_closed(self):
> if self._closed:
> >   raise RuntimeError('Event loop is 

Not raising exception when using form_class in generic CreateView

2018-02-11 Thread Tony
Hi, I am using a package called Django Embed Video 
 for my project. It comes 
with a EmbedVideoField for the model and validation for the URL which 
checks whether the URL is Youtube or Vimeo.
It raises exceptions when using generic create view without using 
customised form(form_class). However, when I use a customised form because 
I want to customise the widgets and css classes, it doesn't raise any 
exceptions. Why is that? Is there a way get the exceptions working with 
form_class?

Another thing is that the data is saved to the db which I can see in Django 
admin. But it is not included in the generic list view. Why?

*models.py*

from django.db import models

from embed_video.fields import EmbedVideoField


Class Video(models.Model):

   title = models.CharField(max_length=30)

   description = models.TextField(blank=True)

   url = EmbedVideoField(verbose_name=‘video’)



*views.py*

from django.views.generic.edit import CreateView

from django.views.generic.list import ListView


class VideoCreate(CreateView):

   model = Video

   form_class = NewVideoForm

class VideoList(ListView):

   model = Video

   ordering = ["-created"]


*forms.py*

from django import forms

from .models import Video


class NewVideoForm(forms.ModelForm):

   description = forms.CharField(widget=forms.Textarea(),

   required=False,

   max_length=4000,

   help_text='The max length of the text is 
4000.')

   url = forms.URLField(label='video', help_text='Please enter a Youtube or 
Vimeo link.')


class Meta:

   model = Video

   fields = ['title', 'description', 'url']

-- 
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/036a9a78-960b-44f0-87ca-795168629785%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Reference field in parent model from the child in a one-to-many relationships during clean

2018-02-11 Thread Daniel Roseman
On Sunday, 11 February 2018 13:41:25 UTC, David Williamson wrote:
>
> Hi,
>
> I have two fields in a model as follows:
>
> society_rowid = models.ForeignKey (
> 'Organisation', on_delete=models.PROTECT, related_name='society',
> blank=True, null=True, db_column='society_rowid',
> limit_choices_to={'type': 'whatson_society'},
> verbose_name='Society',
> )
>
> presented_by = models.CharField (
> max_length=50,
> blank=True,
> )
>
> In the admin interface, if the foreign key is selected and the 
> presented_by is empty, then i want to populate presented_by with the value 
> of the name field at the other end of the relationship. I've tried the 
> following in my clean method for the child object.
>
> if self.society_rowid is not None and self.presented_by is None:
> self.presented_by = str ( self.society )
>
> if self.society_rowid is not None and self.presented_by is None:
> self.presented_by = self.society__name
>
> if self.society_rowid is not None and self.presented_by is None:
> self.presented_by = self.society.name
>
> None of these throw an error but neither do they populate the presented_by 
> field. Any ideas?
>
> Thanks
>
> Dave
>


Presumably, the condition is not true, which also explains why there is no 
error; at least one of these, and possibly all of them, should throw 
AttributeErrors. Are you sure the presented_by field is None, rather than 
an empty string?

Also you should show the rest of your models. Do you actually have a 
`society` field, separate from `society_rowid`?
--
DR.

-- 
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/96044964-41e4-495a-a834-68144c3cd701%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to fetch data from sql server and display on django web pages

2018-02-11 Thread carlos
maybe try with this app
http://django-mssql.readthedocs.io/en/latest/settings.html

On Sun, Feb 11, 2018 at 3:58 AM, PASCUAL Eric  wrote:

> Hi Amit,
>
>
> There is no "Django Web page" as you write in your message, but Web pages
> of the application built on top of the Django framework. Hence how to
> display data depends on how the Web pages of **your** application are
> designed.
>
>
> Second point, one of the roles of Django is to isolate the application
> developer from the raw SQL requests needed to store and retrieve data from
> the underlying data base. This is called an ORM (object relational mapping)
> and it is one of the keystones of the Django framework. The benefit from
> this is that you don't have to deal with SQL requests *(at least for the
> vast majority of the situations)*, but to specify the data model of the
> application as a collection of classes and relations between them. Django
> tools will take care of creating the relational database first, and then
> translate under the hood the object oriented interactions you make with
> your model into the corresponding SQL requests.
>
>
> I've the feeling that you have not fully understood what Django is, what
> Django does and how to write a Django application. So, take no offense,
> but have you read (and understood) at least the introduction (including
> tutorials) documentation of Django ?
>
>
> What is exactly the context of your project, what is it supposed to do,...
> ? The way you are presenting it, it sounds a bit like a student homework.
> Maybe it's not, but...
>
>
> Best regards.
>
>
> Eric
> --
> *From:* django-users@googlegroups.com  on
> behalf of Amit Kadivar 
> *Sent:* Sunday, February 11, 2018 6:37:28 AM
> *To:* Django users
> *Subject:* How to fetch data from sql server and display on django web
> pages
>
> Please Help me.
> How to fetch data from sql server and display them on django web pages
> through nginx web server..
>
>
>
> --
> 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/b5577524-e67d-465f-bb49-e54bca92c88b%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/AM5P193MB00835F3E9901536A3FF319C28CF00%40AM5P193MB0083.
> EURP193.PROD.OUTLOOK.COM
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
att.
Carlos Rocha

-- 
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/CAM-7rO2Gd0Q18_1%2BVyse3ej%2BFmeok6eb2srjEaUajPqr4FbqUw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing Channels 2.0 consumers - problem with routing

2018-02-11 Thread Azamat Galimzhanov
After fixing this issue, here is the updated consumer:


from functools import lru_cache

from asgiref.sync import AsyncToSync
from channels.generic.websocket import WebsocketConsumer


class AuctionConsumer(WebsocketConsumer):
@property
@lru_cache(maxsize=None)
def group_name(self):
path = self.scope['path']
auction_id = path[len('auctions/'):-1]
return 'auction_{}'.format(auction_id)

def connect(self):
AsyncToSync(self.channel_layer.group_add)(self.group_name, 
self.channel_name)
self.accept()

def disconnect(self, close_code):
AsyncToSync(self.channel_layer.group_discard)(self.group_name, 
self.channel_name)

def receive(self, text_data):
AsyncToSync(self.channel_layer.group_send)(
self.group_name,
{
'type': 'auction.bid',
'text': text_data,
},
)

def auction_bid(self, event):
self.send(text_data=event['text'])


 some of my other tests seem to have influence test_consumers, so I set up 
a simplified test case, here it is:

from channels.layers import get_channel_layer
from asgiref.sync import AsyncToSync

import pytest
from channels.testing import WebsocketCommunicator
from auctions.consumers import AuctionConsumer


def test_A():
channel_layer = get_channel_layer()
AsyncToSync(channel_layer.group_send)(
'auction_1',
{
'type': 'auction.bid',
'text': '1'
}
)


@pytest.mark.asyncio
async def test_B():
communicator = WebsocketCommunicator(AuctionConsumer, 'auctions/1/')
connected, subprotocol = await communicator.connect()
assert connected
# Test sending text
await communicator.send_to(text_data='1')
response = await communicator.receive_from()
assert response == '1'
# Close
await communicator.disconnect()


And individually they pass:

 !  ◰³ django_root-FXsg3jFU  /m/k/D/d/auction   41/bidding_websockets 
*…  django_root  pytest -v -s auctions/tests/test_test.py::test_A
5.8s  Sun 11 Feb 2018 10:46:12 PM +06
===
 
test session starts 
===
platform linux -- Python 3.6.3, pytest-3.4.0, py-1.5.2, pluggy-0.6.0 -- 
/home/khazidhea/.local/share/virtualenvs/django_root-FXsg3jFU/bin/python3.6m
cachedir: .pytest_cache
Django settings: core.settings (from ini file)
rootdir: /media/khazidhea/Data/dev/auction/django_root, inifile: setup.cfg
plugins: mock-1.6.3, flake8-0.9.1, django-3.1.2, cov-2.5.1, asyncio-0.8.0, 
celery-4.1.0
collected 1 item

  

auctions/tests/test_test.py::test_A PASSED


 
1 passed in 0.07 seconds 
=
 ◰³ django_root-FXsg3jFU  /m/k/D/d/auction   41/bidding_websockets *…  
django_root  pytest -v -s auctions/tests/test_test.py::test_B  
4053ms  Sun 11 Feb 2018 10:46:20 PM +06
===
 
test session starts 
===
platform linux -- Python 3.6.3, pytest-3.4.0, py-1.5.2, pluggy-0.6.0 -- 
/home/khazidhea/.local/share/virtualenvs/django_root-FXsg3jFU/bin/python3.6m
cachedir: .pytest_cache
Django settings: core.settings (from ini file)
rootdir: /media/khazidhea/Data/dev/auction/django_root, inifile: setup.cfg
plugins: mock-1.6.3, flake8-0.9.1, django-3.1.2, cov-2.5.1, asyncio-0.8.0, 
celery-4.1.0
collected 1 item

  

auctions/tests/test_test.py::test_B PASSED


 
1 passed in 0.09 seconds 
=
Task was destroyed but it is pending!
task: 
 
wait_for=()]> cb=[Future.set_result()]>




But when I run both (I think specifically when B is run after A) I get a 
huge traceback with this in the end:

def _check_closed(self):
if self._closed:
>   raise RuntimeError('Event loop is closed')
E   RuntimeError: Event loop is closed


Full stack trace is here: https://pastebin.com/ZeiMVZD7

Why could it be?

On Saturday, February 10, 2018 at 12:03:53 AM UTC+6, 

Re: Integration between Two apps , Using Django Model

2018-02-11 Thread Etienne Robillard

Hi Dawar,

You might want to check if you have __init__.py in your Taste and 
Taste.TasteApp modules.


HTH,

Etienne


Le 2018-02-11 à 06:45, Dawar Sohail a écrit :



want to import Django app models into another Django app, But I can 
import these models into another app models or view, Plese help me, 








--
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/e931dc2d-b981-41c7-85e8-22d30d71af2c%40googlegroups.com 
.

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


--
Etienne Robillard
tkad...@yandex.com
https://www.isotopesoftware.ca/

--
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/fd587b09-e0f6-5ee4-2d46-d26d686fdad7%40yandex.com.
For more options, visit https://groups.google.com/d/optout.


redirect() doesn't work with a mock object in version 2

2018-02-11 Thread S.j. Sakib
Hello,
When I try to call the django.shortcuts.redirect function with a Mock() 
object from unittest.mock, it results in error. I've found that, the 
problem happens in iri_to_uri function in django.utils.encoding. It used to 
use force_bytes in earlier versions of django.
Any idea how to use a mock object with the redirect object?

Thanks!

Question asked in stackoverflow 


-- 
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/7d000795-267e-4452-a6e3-d9a636d06cb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Reference field in parent model from the child in a one-to-many relationships during clean

2018-02-11 Thread 'David Williamson' via Django users
Hi,

I have two fields in a model as follows:

society_rowid = models.ForeignKey (
'Organisation', on_delete=models.PROTECT, related_name='society',
blank=True, null=True, db_column='society_rowid',
limit_choices_to={'type': 'whatson_society'},
verbose_name='Society',
)

presented_by = models.CharField (
max_length=50,
blank=True,
)

In the admin interface, if the foreign key is selected and the presented_by 
is empty, then i want to populate presented_by with the value of the name 
field at the other end of the relationship. I've tried the following in my 
clean method for the child object.

if self.society_rowid is not None and self.presented_by is None:
self.presented_by = str ( self.society )

if self.society_rowid is not None and self.presented_by is None:
self.presented_by = self.society__name

if self.society_rowid is not None and self.presented_by is None:
self.presented_by = self.society.name

None of these throw an error but neither do they populate the presented_by 
field. Any ideas?

Thanks

Dave

-- 
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/c49ae9cc-0911-4ee2-b863-d867afe5f843%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Integration between Two apps , Using Django Model

2018-02-11 Thread Dawar Sohail



want to import Django app models into another Django app, But I can import 
these models into another app models or view, Plese help me, 






-- 
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/e931dc2d-b981-41c7-85e8-22d30d71af2c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Admin Master-Detail: Dynamically filter selections in detail

2018-02-11 Thread Melvyn Sopacua
On zondag 11 februari 2018 11:36:01 CET Stephan Jaschke wrote:

> If I change any of the Master-Fields I would like the select-boxes in
> the inlines to reflect that change and to show only Fields which are
> bound to that specific csv resp. index-schema.
> 
> It seems that this should be doable via js and ajax but I've no idea how
> this should be done. Any ideas, pointers or hints?

All ajax/js done for you in DAL[1].
-- 
Melvyn Sopacua


[1] 
https://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#filtering-results-based-on-the-value-of-other-fields-in-the-form

-- 
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/3268563.M83KIOcbLC%40fritzbook.
For more options, visit https://groups.google.com/d/optout.


Re: loading script deployment

2018-02-11 Thread Jani Tiainen
Hi.

Since you have so much data to pass and it's in CSV format I would suggest
that instead of pushing data row by row over network upload that data in
CSV format to your API.

Then parse file using forms and save to database.


10.2.2018 22.47 "Leif"  kirjoitti:

Hi Dylan,
Thank you for the great input. Hopefully django REST interface will be able
to handle the post for large amount of data (~500k rows) without problem.
Best,
Leif


On Saturday, February 10, 2018 at 10:14:29 AM UTC-5, Leif wrote:
>
> Dear Django,
>
> Sorry if this question has been answered. I have a Django based web
> application and I just developed a loading script to upload data to
> database using django model. The code is located under management/commands.
> Here is the commands to run the script:
>
> $source ./appenv/bin/activate appenv
> (appenv)$python manage.py load_data data_file.csv
>
> I would like to deploy this script to my client. I don't want to send the
> entire code of web application. How do I do it?
>
> Thank you in advance for your help.
>
> Best,
>
> Leif
>
-- 
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/4413e8af-6203-47e9-9537-720f224e2873%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/CAHn91odD33dcz9nkRT0hwQgk6qwYeuYDjryf1JwiXS_jutZ%3DZw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Admin Master-Detail: Dynamically filter selections in detail

2018-02-11 Thread Stephan Jaschke
Hi all.

I'm trying to implement a customizable import-module for csv-data into
elasticsearch-indices. The use may select a csv-schema with given fields
and create a mapping to arbitary indices. This mapping schould be done
on field level.

So I ended up with following simplified models:

class CSVSchemaField(models.Model):
schema = models.ForeignKey(
'CSVSchema',
related_name'fields'
)
name = models.CharField()

class CSVSchema(models.Model):
name = models.CharField()

class IndexSchemaField(models.Model):
schema = models.ForeignKey(
'IndexSchema',
related_name'fields'
)
name = models.CharField()

class IndexSchema(models.Model):
name = models.CharField()

... and the mapping models ...

class MappingFieldMap(models.Model):
mapping = models.ForeignKey(
'Mapping',
related_name'fields'
)
csv_field = models.ForeignKey(
CSVSchemaField,
)
index_field = models.ForeignKey(
IndexSchemaField,
)

class Mapping(models.Model):
csv_schema = models.ForeignKey(
CSVSchema,
)
index_schema = models.ForeignKey(
IndexSchema
)

For the admin I created a standard-form for the Mapping with
tabular-inlines for the MappingFieldMap. This gave me two select-boxes
on top and a couple of inlines below, each with to select-boxes.

If I change any of the Master-Fields I would like the select-boxes in
the inlines to reflect that change and to show only Fields which are
bound to that specific csv resp. index-schema.

It seems that this should be doable via js and ajax but I've no idea how
this should be done. Any ideas, pointers or hints?

Regards
Stephan

-- 
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/p5p66i%2471u%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.


Re: How to fetch data from sql server and display on django web pages

2018-02-11 Thread PASCUAL Eric
Hi Amit,


There is no "Django Web page" as you write in your message, but Web pages of 
the application built on top of the Django framework. Hence how to display data 
depends on how the Web pages of *your* application are designed.


Second point, one of the roles of Django is to isolate the application 
developer from the raw SQL requests needed to store and retrieve data from the 
underlying data base. This is called an ORM (object relational mapping) and it 
is one of the keystones of the Django framework. The benefit from this is that 
you don't have to deal with SQL requests (at least for the vast majority of the 
situations), but to specify the data model of the application as a collection 
of classes and relations between them. Django tools will take care of creating 
the relational database first, and then translate under the hood the object 
oriented interactions you make with your model into the corresponding SQL 
requests.


I've the feeling that you have not fully understood what Django is, what Django 
does and how to write a Django application. So, take no offense, but have you 
read (and understood) at least the introduction (including tutorials) 
documentation of Django ?


What is exactly the context of your project, what is it supposed to do,... ? 
The way you are presenting it, it sounds a bit like a student homework. Maybe 
it's not, but...


Best regards.


Eric

From: django-users@googlegroups.com  on behalf 
of Amit Kadivar 
Sent: Sunday, February 11, 2018 6:37:28 AM
To: Django users
Subject: How to fetch data from sql server and display on django web pages

Please Help me.
How to fetch data from sql server and display them on django web pages through 
nginx web server..




--
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/b5577524-e67d-465f-bb49-e54bca92c88b%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/AM5P193MB00835F3E9901536A3FF319C28CF00%40AM5P193MB0083.EURP193.PROD.OUTLOOK.COM.
For more options, visit https://groups.google.com/d/optout.