How to create a queryset to filter jsonb fields with __ in key name

2019-05-08 Thread Rakesh Ranjan
I have a jsonb field in one of my django model. There are few key value 
pairs in this json in table with __ in key name. Eg json:
```
data: {'base_cover__tenure': 2,
 'base_cover__variant': '125 Z',
}
```
How can I create a queryset to filter on these fields?
I have tried this  
```MyModel.objects.filter(data__base_cover__tenure__gte=1)```, which 
obviously doesn't work.

-- 
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/662eb68a-ea7d-48c7-bbff-7215b988d695%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Oracle ORA-03124 Two-task internal error

2019-05-08 Thread Dan Davis
Running my migrations with Django 1.11. (1.11.20), fails with the Oracle 
error ORA-03124 Two-task internal error.
I have tried this with Oracle instantclient 12.1.0.1 and 18.5.0.0., and 
several other versions of cx_Oracle.

There are no migrations to make, but I get the following error, always in 
the same place, the post_migrate handler for contentypes, after auth.



manage.py migrate -v 3
[2019-05-08 17:23:23,792] INFO nlm.occs.dbp retrieved password for 
mplusmon_dev@medplus_dev
Operations to perform:
  Apply all migrations: auth, casauth, contenttypes, django_cas_ng, 
mplusmon, sessions
Running pre-migrate handlers for application mplusmon
Running pre-migrate handlers for application auth
Running pre-migrate handlers for application contenttypes
Running pre-migrate handlers for application sessions
Running pre-migrate handlers for application django_filters
Running pre-migrate handlers for application django_cas_ng
Running migrations:
  No migrations to apply.
Running post-migrate handlers for application mplusmon
Running post-migrate handlers for application auth
Traceback (most recent call last):
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\db\backends\utils.py",
 
line 64, in execute
return self.cursor.execute(sql, params)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\db\backends\oracle\base.py",
 
line 497, in execute
return self.cursor.execute(query, self._param_generator(params))
cx_Oracle.DatabaseError: ORA-03124: two-task internal error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\davisda4\workspace\mplusmonitor\manage.py", line 15, in 

execute_from_command_line(sys.argv)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\core\management\__init__.py",
 
line 364, in execute_from_command_line
utility.execute()
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\core\management\__init__.py",
 
line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\core\management\base.py",
 
line 283, in run_from_argv
self.execute(*args, **cmd_options)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\core\management\base.py",
 
line 330, in execute
output = self.handle(*args, **options)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\core\management\commands\migrate.py",
 
line 227, in handle
self.verbosity, self.interactive, connection.alias, 
apps=post_migrate_apps, plan=plan,
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\core\management\sql.py",
 
line 53, in emit_post_migrate_signal
**kwargs
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\dispatch\dispatcher.py",
 
line 193, in send
for receiver in self._live_receivers(sender)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\dispatch\dispatcher.py",
 
line 193, in 
for receiver in self._live_receivers(sender)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\contrib\contenttypes\management\__init__.py",
 
line 119, in create_contenttypes
content_types, app_models = get_contenttypes_and_models(app_config, 
using, ContentType)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\contrib\contenttypes\management\__init__.py",
 
line 96, in get_contenttypes_and_models
for ct in 
ContentType.objects.using(using).filter(app_label=app_config.label)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\db\models\query.py",
 
line 250, in __iter__
self._fetch_all()
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\db\models\query.py",
 
line 1121, in _fetch_all
self._result_cache = list(self._iterable_class(self))
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\db\models\query.py",
 
line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\db\models\sql\compiler.py",
 
line 899, in execute_sql
raise original_exception
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\db\models\sql\compiler.py",
 
line 889, in execute_sql
cursor.execute(sql, params)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\db\backends\utils.py",
 
line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\db\backends\utils.py",
 
line 64, in execute
return self.cursor.execute(sql, params)
  File 
"C:\Users\davisda4\PythonEnvs\mplusmon\lib\site-packages\django\db\utils.py", 
line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
  File 

How to make the mock object iterable ['TypeError: 'Mock' object is not iterable'] Need to Mock the django query that is iterating through for loop

2019-05-08 Thread Shashank Gupta
I am trying to mock the below django query object : 
   
1.) if MyModel.objects.filter(data='some_data').exists():
then 2.) for row in MyModel.objects.filter(ListId=id):

I am trying to test below django query inside my method.

def my_method(some_parameter):
 if formsList.objects.filter(data=some_data).exists():
for item in formsList.objects.filter(data1='data1',data2='data2'):
formNameInDb = (item.fileId).formName
if formNameInDb == formName:
return True

Below is my approach:

@mock.patch('MyModel.objects')  
def test_checkCombinationOfStateAndProduct(self, formsList_mock):

formsList_mock_data = mock.MagicMock(spec=MyModel)
formsList_mock_data.fileId.formName ='test data'

formsList_queryset = Mock()
formsList_mock.filter.return_value = formsList_queryset

# formsList_mock.filter.return_value = [formsList_queryset] 

formsList_queryset.exists.return_value = True


For the query 1). 
It is working like I am able to mockupto  **if 
formsList.objects.filter(data=some_data).exists()**

but again for the query 
2) for item in formsList.objects.filter(data1='data1',data2='data2'):
I am getting **mock object(formsList_queryset) should be iterable**
so if I make it iterable like this **[formsList_queryset]**.

Then i am getting error **" AttributeError: 'list' object has no attribute 
'exists'**.

I guess it is because after making the mock object iterable it is behaving 
like list so it does not has the exists attribute.

My problem is I am not able to make the mock object(formsList_queryset) 
iterable so that it will work in the both above mentioned query.

Is there other way mock both query to handle this issue.

Can anyone help to solve the chain queries. Any help or lead, I will really 
appreciate.
Please let me know if any information required.

-- 
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/f5558d18-6872-4715-b5e2-8f2baa627478%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


possible bug: test loader fails if models/__init__.py defined

2019-05-08 Thread Matthew Hegarty
Hi

I have imported my model classes in models/__init__.py (as described in docs 

):

You must define or import all models in your application’s models.py or 
> models/__init__.py. Otherwise, the application registry may not be fully 
> populated at this point, which could cause the ORM to malfunction.


However after doing this, running tests with ./manage.py test -k causes the 
unittest loader to fail with:

ERROR: myapp.api.models (unittest.loader._FailedTest)
--
ImportError: Failed to import test module: myapp.api.models
Traceback (most recent call last):
  File "/usr/lib/python3.6/unittest/loader.py", line 462, in _find_test_path
package = self._get_module_from_name(name)
  File "/usr/lib/python3.6/unittest/loader.py", line 369, in 
_get_module_from_name
__import__(name)
  File "/myapp/api/models/__init__.py", line 5, in 
from .api_key import ApiKey
  File "/myapp/api/models/api_key.py", line 17, in 
class ApiKey(models.Model):
  File "/-Z_V0-nQl/lib/python3.6/site-packages/django/db/models/base.py", 
line 111, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class myapp.api.models.api_key.ApiKey doesn't declare 
an explicit app_label and isn't in an application in INSTALLED_APPS.


The workaround is to run: ./manage.py test -k api.tests  
(then the test loader doesn't try to load __init__.py)

This issue is discussed on SO 

 
- I wondered if it could be a bug?

-- 
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/4f622eb1-d3fc-4fe9-a6fa-e097f7257130%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: reg: Django model sequense of the fields

2019-05-08 Thread Vinicius Assef
Is it a problem?

On Wed, 8 May 2019 at 12:52, 'Amitesh Sahay' via Django users <
django-users@googlegroups.com> wrote:

> Hello Users,
>
> I am seeing a very strange issue with my Django models.
> in my models.py, I have 21 fields. Out of them , the 6th field is
> DASHBoard. However, when I see those fields in my postgres DB through
> PgAdminIII, it is listed at the very end of the list.
>
> Sorry, for security reasons I couldn't give the list of the fields here.
>
> Could there be any explanation for this situation?
>
> Regards,
> Amitesh Sahay
>
> --
> 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/1048828608.1995499.1557330720573%40mail.yahoo.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/CAFmXjSBYvavhGy83J4zcMg526J90h4c7GreT%3D3Fofg9vs3OVEg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


reg: Django model sequense of the fields

2019-05-08 Thread 'Amitesh Sahay' via Django users
Hello Users, 
I am seeing a very strange issue with my Django models. in my models.py, I have 
21 fields. Out of them , the 6th field is DASHBoard. However, when I see those 
fields in my postgres DB through PgAdminIII, it is listed at the very end of 
the list. 
Sorry, for security reasons I couldn't give the list of the fields here.
Could there be any explanation for this situation?


Regards,
Amitesh Sahay

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


Re: Need help with project

2019-05-08 Thread Guru Murthy
Try django2 by example by Antonio mele will guide how to do project with
django


Regards,
Gurumurthy P

On Wed, 8 May, 2019, 8:32 PM Rob W,  wrote:

> There are a few of us in a group slack who are trying to build a working
> production django ap for reporting.
> We are looking for someone who really knows Django to guide us through
> this project.
>
> We are all really hoping that someone will be kind enough to guide us and
> help us build this app.
>
> it's simple, we are connecting to a remote mysql db, which i also setup in
> Azure for sync purposes.
>
> so we are creating a login capability, reset, forgot password, etc.
>
> then on the dashboard we simply want to generate reporting from this
> remote db.
>
> I am hopeful someone will help us.
>
>
> --
> 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/c33feee5-4001-4bf1-b8e8-0f0c9c9517c2%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/CAMgkGLU8h%3D7qAB5GVmGoThc9Mmf2OXDvqDyKWBsuMy5OcoCeRQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Need help with project

2019-05-08 Thread Rob W
There are a few of us in a group slack who are trying to build a working 
production django ap for reporting. 
We are looking for someone who really knows Django to guide us through this 
project.

We are all really hoping that someone will be kind enough to guide us and 
help us build this app.

it's simple, we are connecting to a remote mysql db, which i also setup in 
Azure for sync purposes.

so we are creating a login capability, reset, forgot password, etc.

then on the dashboard we simply want to generate reporting from this remote 
db.

I am hopeful someone will help us.


-- 
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/c33feee5-4001-4bf1-b8e8-0f0c9c9517c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to Create Program to get current temperature of computer cpu?

2019-05-08 Thread Mayur Bagul
Hello community,

i searched on google bout this and what i found was psutil is no longer 
having check temperature attribute.

im not getting how to do this.

help me with this !

thanking you,
Mayur Bagul.

-- 
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/9d3c8e19-5371-4b9b-a814-bf90fdc53a96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: no migrations to apply after deleting a field in models

2019-05-08 Thread Nelson Varela
Don't delete the 0001_initial file!
That is your first state. Just delete the field from you model and do 
makemigrations again.. You wil get a 0002_ file which deletes the field.


-- 
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/2dab1505-795b-491b-9bf9-18d65ca85634%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it possible to create website like Squarespace or Wix in django?

2019-05-08 Thread Zill Facon
I guess that you can create any site like in squarespaceor Wix in any 
Website builder from Google sites till Mobirise. 

-- 
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/8a25be23-d0af-4fd9-8f75-d5ee4e7e5f8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Suscribe

2019-05-08 Thread Ousmane BARRA
Hi,
How can i susbcribe in this list?

-- 
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/CABwXbd76n3w-Ou0iqvL4VqGFPa-a4U7A%3D69_to%3DH0hh1%2BYiRkA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Custom field on admin.py - FieldDoesNotExist when using RelatedFieldWidgetWrapper

2019-05-08 Thread Naran Khetani
Hello Users,
Hoping for someone to help me with this, I have a admin form which I am 
overwriting as below:

admin.py

def add_related_field_wrapper(form, col_name):
rel_model = form.Meta.model
rel = rel_model._meta.get_field(col_name).rel
form.fields[col_name].widget = RelatedFieldWidgetWrapper(
form.fields[col_name].widget,
rel,
admin.site,
can_add_related=True,
can_change_related=True
)


class DocumentItemsForm(forms.ModelForm):

tags = ModelMultipleChoiceField(label="Tags", required=False, queryset=
Terms.objects.filter(termtypeid__name='tag'))
categorys = ModelMultipleChoiceField(label="Categorys", required=False, 
queryset=Terms.objects.filter(termtypeid__name='category'))

def __init__(self, *args, **kwargs):
super(DocumentItemsForm, self).__init__(*args, **kwargs)
add_related_field_wrapper(self, 'tags')

@admin.register(Documentitems)
class DocumentitemsAdmin(admin.ModelAdmin):

form = DocumentItemsForm
save_as = True


I get the below exception:

Django Version: 2.1.7
Exception Type: FieldDoesNotExist
Exception Value: Documentitems has no field named 'tags'

The actual model does not have those fields above, I have a feeling its 
looking up the actual model which is why its not finding the field. In 
essence what im trying to do is add a custom field that does not exist in 
the model which works fine, however i need to be able to add the plus 
button next to the field which allows the user to add a new record and ive 
be lead to the above solution to achieve this.

-- 
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/1950c6dd-3fa7-4cea-a5c5-4b87c68c4300%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


no migrations to apply after deleting a field in models

2019-05-08 Thread amirreza taherkhani
I have this models:

class Genre(models.Model):
genre   = models.CharField(max_length=100)

def __str__(self):
return self.genre


class Book(models.Model):
book_name   = models.CharField(max_length=150)
summary = models.TextField(max_length=1000, null=True,blank=True)
author  = models.ForeignKey('Author', on_delete=models.CASCADE)
genre   = models.ManyToManyField(Genre)
status = [
('a', 'available'),
('b', 'borrowed'),
('r', 'reserved'),
]
book_status = models.CharField(max_length=1, choices=status, default='a')

def __str__(self):
return '{0}({1})'.format(self.book_name, self.author)

def get_absolute_url(self):
return reverse('main_app:book-detail', args=[self.id])


class Author(models.Model):
first_name  = models.CharField(max_length=200)
last_name   = models.CharField(max_length=200)
rate= models.IntegerField(default=0)

def __str__(self):

return '{0} {1}'.format(self.first_name,self.last_name)

and i deleted an uuidfield from book table...
then i deleted this file -> 0001_initial.py
and then run : py manage.py makemigrations and migrate
but migrate is not available to recognize the changes :

C:\Users\amir\Documents\GitHub\simple_library> py  manage.py makemigrations
Migrations for 'main_app':
  main_app\migrations\0001_initial.py
- Create model Author
- Create model Book
- Create model Genre
- Add field genre to book

C:\Users\amir\Documents\GitHub\simple_library> py manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, main_app, sessions
Running migrations:
  No migrations to apply.

what should i do now?

-- 
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/CAPgudTetbg4a27E-sJD-uqZgdiEtXd4-UrGOK79Herkyqns-Eg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Can't reference related object inside model property

2019-05-08 Thread Ajat Prabha
I have to display a calculated property in the model admin's list_display.

```python
class A:
# attributes

class B:
a = models.OneToOneField(A, on_delete=models.CASCADE, 
related_name='b_obj')
timestamp = models.DateTimeField()

class AProxy(A):
@property
def calc_prop(self):
return self.b_obj.timestamp if self.b_obj else 'Some text'

class Meta:
proxy = True
```

When I display this `calc_prop` in model admin's list view I always get `-` 
if there is no corresponding `b_obj` related object on AProxy's object. 
What am I doing wrong here?

Thanks!

-- 
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/ff382c07-63fb-4be9-a011-01da80e33f09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Fresher

2019-05-08 Thread Sanjay Chandak
I am a fresher in Django and know few annotation and using that I have
created the dummy application of an application on which I am working in my
office.

Do I need to go more with the annotations or conditions is fine?

I am looking for the job in python. So apart from the Django framework what
else need to study?

Thanks
Sanjay

-- 

*WITH REGARDS*

*Sanjay Chandak*

*student of MNNIT, Allahabad*

*ECE Department*

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


Re: Unit conversions between model field value and form field value

2019-05-08 Thread Jani Tiainen
Hi.

You could create custom form field that makes conversions both ways.

ke 8. toukok. 2019 klo 1.25 Tim Bell  kirjoitti:

> Hi,
>
> I have a model with an integer field storing a duration in hours, while I
> want to present that to users in a form in days. (The choice of these
> different units is imposed by other factors not under my control.)
>
> So, when saving a form, I need to convert a value in days to hours by
> multiplying by 24. I've done that with a clean_() method on
> the form, as described at
> https://docs.djangoproject.com/en/2.2/ref/forms/validation/. That works
> fine for when saving a new model.
>
> When editing an existing model however, I need to take the value from the
> model stored in hours, and convert that to days for display in the edit
> form. I've considered various places where I could do that conversion, for
> instance in the edit view, or the form __init__() method, or the model
> field's value_from_object() method, but none of those choices seem like
> the obvious choice, and I can't find a recommendation for how to do this
> either.
>
> What would you suggest? And is the recommended approach actually
> documented somewhere that I've missed?
>
> Thanks,
>
> Tim
>
> --
> 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/0d786f87-8c6e-4e0d-abc5-aaa66ab4da2a%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/CAHn91od3y53TA%3DYt_x8noAdPYBni8Q4P8mSorJrb2Y%2BD6zcffg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is it Possible to run django locally without internet connection

2019-05-08 Thread Idris Adegbite
Alright, Thanks alot Mr Shashank, Really appreciate, will try it out now

On Wed, May 8, 2019 at 3:19 AM Shashank Singh 
wrote:

> Run server with command ./manage.py runserver 0:8000. 0 here tells that
> any one on the same network can access the project's urls like this.
> Suppose your laptop's ip is 10.0.0.156 so from your phone go to
> 10.0.0.156:8000/admin and you are connected to your django projects. You
> must be on the same network/lan. It may or may not have a working internet
> connection.
>
> On Tue, May 7, 2019, 9:18 PM Rob Gmail  wrote:
>
>> Yes you can.  I do it for an IOT device that we have using Django/python,
>> many times it does not have an Internet connection but runs fine.
>>
>> Rob
>> 203-671-6514
>> Sent from my mobile device, please excuse the typos.
>>
>> On May 7, 2019, at 11:38 AM, Idris Adegbite 
>> wrote:
>>
>> Good day guys, Please can i run django on laptop without internet
>> connection.
>>  if yes, Please kindly help me out with the procedures.
>>
>> I am having issues connecting my  phone and laptop and i dont want that
>> to slow down my learning.
>> Any help would be appreciated
>>
>> --
>> 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/809870ae-92a1-4881-96ae-838d9342ee0b%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/A015232A-FE14-4BA8-9C45-70E4C6CD6F23%40gmail.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/CAD-d1sbsFh7TxOc-oDtDSnkEeDFkQV4xa26xMUaFLaP5Zo-Dow%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/CAN%3DhNM%2BE32WMhLo5FU3_JFu6j2Eo%3DQGdEveo-mg3FY4_cw%2BnsA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: models

2019-05-08 Thread Mohammad Etemaddar
The one who should have foreign key is is filter, box and barel to shelf.
Then you can access them from shelf:
Shelf0.boxs
Shelf0.barels
And shelf0.filters

Note that you can set the relation_name in foreign key so that you can use
the related name instead of filters, boxs and barels

On Wed, 8 May 2019 11:05 Robin Riis,  wrote:

> if i have a model like
>
> class ShelfManager(models.Manager):
>
> use_for_related_fields = True
>
> def create_cabinet(self, name, number_of_shelfs):
>
> cabinet = self.create(name=name, number_of_shelfs=number_of_shelfs)
>
> created_shelfs = 0
>
> while created_shelfs < number_of_shelfs:
>
> cabinet.shelfs.create()
>
> created_shelfs += 1
>
> return place
>
>
> class Cabinet(models.Model):
>
> name = models.CharField(max_length=50, unique=True)
>
> number_of_shelfs = models.IntegerField
>
> shelfs = ShelfManager()
>
> class Shelfs(models.Model):
>
> place = models.ForeignKey(Cabinet, on_delete=models.CASCADE, null=True,
> blank=True, related_name='shelfs')
> ...
>
> and i want shelf to hold either model Box, Filter or Barrel
> but not sure which approach to use :P
>
>
> --
> 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/CAPLZMbPTNJ8OavQiaUpdELVH4wo9V9p94zkFWDwZS4sXdZtS8g%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/CALJt1ntd4roJy_KOpXRDb9%2BfGLeue2gkJSQi5Q8cKXT3%2B8zk%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


models

2019-05-08 Thread Robin Riis
if i have a model like

class ShelfManager(models.Manager):

use_for_related_fields = True

def create_cabinet(self, name, number_of_shelfs):

cabinet = self.create(name=name, number_of_shelfs=number_of_shelfs)

created_shelfs = 0

while created_shelfs < number_of_shelfs:

cabinet.shelfs.create()

created_shelfs += 1

return place


class Cabinet(models.Model):

name = models.CharField(max_length=50, unique=True)

number_of_shelfs = models.IntegerField

shelfs = ShelfManager()

class Shelfs(models.Model):

place = models.ForeignKey(Cabinet, on_delete=models.CASCADE, null=True,
blank=True, related_name='shelfs')
...

and i want shelf to hold either model Box, Filter or Barrel
but not sure which approach to use :P

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