Re: Django models and json integration

2019-08-10 Thread Suraj Thapa FC
Can  you pls elaborate or have any working code

On Sat, 10 Aug, 2019, 9:40 PM Andrew C.,  wrote:

> Two options:
>
> 1) Save the JSON files and link it with a FileField
>
> 2) Use PostgreSQL’s Django-specific JSONField.
>
> On Sat, Aug 10, 2019 at 9:46 AM Suraj Thapa FC 
> wrote:
>
>> How can I linked a JSON file with my db... Json files contains the key
>> value pair of the user data..
>> If the id in the db and the id in the json files matches i can fetch and
>> read it..
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAPjsHcFbqtWJmDXrbafemf8TQkX9gROW-TxOvirvjsFut%3D5A1w%40mail.gmail.com
>> 
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJVmkNkTkjYFOvwPO%3DRrdtephow%2BH4rJNk0KQNriWmO%2Bm3hEmw%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPjsHcECRvr3sPTPt06CZwcVpWWKTbJ%3DYHorvco49M2_B%2BNwJw%40mail.gmail.com.


Re: Django models and json integration

2019-08-10 Thread Andrew C.
Two options:

1) Save the JSON files and link it with a FileField

2) Use PostgreSQL’s Django-specific JSONField.

On Sat, Aug 10, 2019 at 9:46 AM Suraj Thapa FC 
wrote:

> How can I linked a JSON file with my db... Json files contains the key
> value pair of the user data..
> If the id in the db and the id in the json files matches i can fetch and
> read it..
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPjsHcFbqtWJmDXrbafemf8TQkX9gROW-TxOvirvjsFut%3D5A1w%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJVmkNkTkjYFOvwPO%3DRrdtephow%2BH4rJNk0KQNriWmO%2Bm3hEmw%40mail.gmail.com.


Re: django models

2019-05-07 Thread sachinbg sachin
On Tue, May 7, 2019, 12:35 PM Soumen Khatua  Hi Folks,
>
> I didn't  understand this code please help me to understand this code.
>
> class AddressQueryset(models.QuerySet):
> def annotate_default(self, user):
> # Set default shipping/billing address pk to None
> # if default shipping/billing address doesn't exist
> default_shipping_address_pk, default_billing_address_pk = None,
> None
> if user.default_shipping_address:
> default_shipping_address_pk = user.default_shipping_address.pk
> if user.default_billing_address:
> default_billing_address_pk = user.default_billing_address.pk
> return user.addresses.annotate(
> user_default_shipping_address_pk=Value(
> default_shipping_address_pk, models.IntegerField()),
> user_default_billing_address_pk=Value(
> default_billing_address_pk, models.IntegerField()))
>
>
> default_shipping_address & default_billing_address_pk is available in my
> User table it is a foreignkey of Address table  and  addresses is also
> avialable in my User table as ManytoManytoField refering to same Address
> Table and the last i'm using this inside Address table just like this :
> objects = AddressQueryset.as_manager()
>
>
>
> Thank You
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPUw6Wbb9Emmq0aODhK9GmT9Z8X0TMQtSOsPJ-SA-99mpdT6sg%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/CAOs61rwsOdXyWTi%2BxhWO%3DybO2sLF77dmris_Au0Q1gsrUMhuCQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2019-05-07 Thread Soumen Khatua
Yes,You are right as_data is custom made function inside the same
class,here is the code:



def as_data(self):
"""Return the address as a dict suitable for passing as
kwargs.Result does not contain the primary key or an associated user."""
data = model_to_dict(self,exclude=['id','user'])
if isinstance(data['country'], Country):
data['country'] = data['country'].code
if isinstance(data['phone'], PhoneNumber):
#as_e164 is a phonenumber format information
data['phone'] = data['phone'].as_e164
return data


But here other is an argument so we need to pass it then without passing
how we can compare with self.as_data varibale?

Thank you for your response.

On Tue, May 7, 2019 at 2:19 AM Skyisblue  wrote:

> Soumen,
>
> The function looks to compare two Address objects. The as_data() call is
> custom made. I saw it documented in your other post. It removes the Primary
> Key and User from the Address object. I presume this is so they can compare
> the hash of one address to the hash of another.
>
> Regards,
> Joe
>
> On Mon, May 6, 2019 at 6:03 AM Soumen Khatua 
> wrote:
>
>> Hi Folks,
>>
>> How this underline code works?
>>
>>
>> models.py
>>
>> class Address(models.Model):
>> first_name = models.CharField(max_length=256, blank=True)
>> last_name = models.CharField(max_length=256, blank=True)
>> company_name = models.CharField(max_length=256, blank=True)
>> street_address_1 = models.CharField(max_length=256, blank=True)
>> street_address_2 = models.CharField(max_length=256, blank=True)
>> city = models.CharField(max_length=256, blank=True)
>> city_area = models.CharField(max_length=128, blank=True)
>> postal_code = models.CharField(max_length=20, blank=True)
>> country = CountryField()
>> country_area = models.CharField(max_length=128, blank=True)
>> phone = PossiblePhoneNumberField(blank=True, default='')
>>
>>
>> *def __eq__(self, other):*
>> *   return self.as_data() == other.as_data()*
>> * __hash__ = models.Model.__hash__*
>>
>>
>> Thank you.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAPUw6WY-pNGnPBHzDA%3DiRZUHY7NrmK30_dMbKiQpe%2B1n%2ByW%2BQQ%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/CAGgUuiuun1NebT1V5r2v3GGjSCJ4RybUw9Fsn1g4M6x1ei2VQw%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/CAPUw6Wbdko08d210HbV5uv8EBeWiC6Q%3D8LKdfyyYKHN--7__pA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2019-05-06 Thread Skyisblue
Soumen,

The function looks to compare two Address objects. The as_data() call is
custom made. I saw it documented in your other post. It removes the Primary
Key and User from the Address object. I presume this is so they can compare
the hash of one address to the hash of another.

Regards,
Joe

On Mon, May 6, 2019 at 6:03 AM Soumen Khatua 
wrote:

> Hi Folks,
>
> How this underline code works?
>
>
> models.py
>
> class Address(models.Model):
> first_name = models.CharField(max_length=256, blank=True)
> last_name = models.CharField(max_length=256, blank=True)
> company_name = models.CharField(max_length=256, blank=True)
> street_address_1 = models.CharField(max_length=256, blank=True)
> street_address_2 = models.CharField(max_length=256, blank=True)
> city = models.CharField(max_length=256, blank=True)
> city_area = models.CharField(max_length=128, blank=True)
> postal_code = models.CharField(max_length=20, blank=True)
> country = CountryField()
> country_area = models.CharField(max_length=128, blank=True)
> phone = PossiblePhoneNumberField(blank=True, default='')
>
>
> *def __eq__(self, other):*
> *   return self.as_data() == other.as_data()*
> * __hash__ = models.Model.__hash__*
>
>
> Thank you.
>
>
>
>
>
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPUw6WY-pNGnPBHzDA%3DiRZUHY7NrmK30_dMbKiQpe%2B1n%2ByW%2BQQ%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/CAGgUuiuun1NebT1V5r2v3GGjSCJ4RybUw9Fsn1g4M6x1ei2VQw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2018-08-14 Thread Andréas Kühne
Hi,

The error is pretty self explanatory.

There is a missing migration file:
 (u'training_kits', u'0003_auto_20160914_0722')

So check your training_kits app for a migration that is called
0003_auto_20160914_0722.py.

This migration is a dependency for the migration:
0004_tasktype_training_kit.py in the task_types app.

Regards,

Andréas

2018-08-14 8:26 GMT+02:00 Ramandeep Kaur :

> hi guys, i need your help
> when i run makemigrations command,  i got error:
> django.db.migrations.exceptions.NodeNotFoundError: Migration
> task_types.0004_tasktype_training_kit dependencies reference nonexistent
> parent node (u'training_kits', u'0003_auto_20160914_0722')
>
> On Fri, Aug 10, 2018 at 8:21 PM Kasper Laudrup 
> wrote:
>
>> Hi Ramandeep,
>>
>> The problem is pretty much the same as before: Mismatched parentheses,
>> but I'll leave to you to figure out where. It's pretty easy to spot.
>>
>> Did you find an editor that helps you syntax check python code?
>>
>> It'll make your life a lot easier.
>>
>> Kind regards,
>>
>> Kasper Laudrup
>>
>> On August 10, 2018 3:42:56 PM GMT+02:00, Ramandeep Kaur <
>> hpramandeepkau...@gmail.com> wrote:
>>>
>>> thanks i got my  mistake but now again i am getting an error.
>>> my urls.py:
>>> from django.conf.urls import patterns, include, url
>>> from django.contrib import admin
>>> from django.views.generic import TemplateView
>>>
>>> from rest_framework_nested import routers
>>>
>>> from rest_auth.views import LogoutView
>>>
>>> from locations.views import LocationViewSet
>>>
>>> from tasks.views import TaskViewSet, BeneficiaryTasksView,
>>> AssignedTasksView, CreatedTasksView, tasks_assign, tasks_smart_assign,
>>> FilterTasksView, PaginatedTaskViewSet, get_tasks_length,
>>> get_tasks_page_size, export_tasks_view, create_bulk_tasks,
>>> import_data_view, get_filtered_tasks_length, PledgedTasksView,create_task
>>> from task_types.views import TaskTypeViewSet
>>> from task_status.views import TaskStatusViewSet
>>> from feedback_types.views import FeedbackTypeViewSet
>>> from organisations.views import OrganisationViewSet
>>> from authentication.views import UserViewSet
>>> from user_profiles.views import *
>>> from forms.views import FormViewSet, FormDataViewSet, DataByFormView,
>>> PersistentFormViewSet, PersistentFormDataView,export_filtered_form_data
>>> from training_kits.views import *
>>> from stages.views import StageViewSet
>>> from notes.views import NoteViewSet, BeneficiaryNotesView,
>>> CreatedNotesView
>>> from user_messages.views import MessageViewSet,
>>> BeneficiaryMessagesView, SentMessagesView
>>> from todos.views import TodoViewSet, AssignedTodosView,
>>> CreatedTodosView, BeneficiaryTodosView
>>> from tags.views import (TagViewSet, LightTagViewSet, UserTagsView,
>>> UserLightTagsView,
>>> RemoveUserFromTag, RemoveExclusiveTagFromTag,
>>> AddTagToUser, AddTagsToUser, AddExclusiveTagToTag)
>>> from message_templates.views import MessageTemplateViewSet
>>> #from calls.views import CallViewSet, BeneficiaryCallsView,
>>> CallerCallsView
>>> from task_status_categories.views import TaskStatusCategoryViewSet,
>>> CreatedTaskStatusCategoriesView, getTaskCompletedFlagChoices
>>> #from actions.views import get_action_classes, ActionViewSet
>>> from events.views import EventViewSet
>>> from event_conditions.views import EventConditionViewSet,
>>> getEventConditionTypes, HelplineEventConditionsView,
>>> NormalEventConditionsView
>>> from hooks.views import HookViewSet
>>> from ivrs.views import IVRViewSet, BeneficiaryIVRsView, SentIVRsView,
>>> FeedbackIVRView
>>> from ivr_templates.views import IVRTemplateViewSet
>>> from exotel.views import MissedCall, ExotelViewSet, IncSMS, Lottery,
>>> DostPaid, DostMother, DostFather
>>> from guilds.views import GuildViewSet, add_users_to_guild
>>> from notices.views import NoticeViewSet
>>> from spaces.views import SpaceViewSet
>>> from space_types.views import SpaceTypeViewSet, add_spaces
>>> from interests.views import InterestViewSet, LightInterestViewSet,
>>> AddInterestsToUser, RemoveInterestsFromUser, UserInterestsView
>>> from pledges.views import PledgeViewSet, TaskPledgesView,
>>> UserPledgesView
>>> from party_invitations.views import PartyInvitationViewSet,
>>> SentPartyInvitationsView, ReceivedPartyInvitationsView
>>> from task_comments.views import TaskCommentViewSet,
>>> TaskCommentDetailedViewSet, TaskCommentsView, CommentedCommentsView
>>> from follows.views import FollowViewSet, FollowerFollowsView,
>>> FollowedFollowsView, get_follow
>>> #from centers.views import CenterViewSet
>>> from locations.views import LocationViewSet
>>> from kits.views import KitViewSet
>>> from parents.views import ParentViewSet,ParentWorkerListViewSet
>>> from worker.views import WorkerViewSet
>>> from child.views import ChildViewSet
>>> from payments.views import PaymentViewSet,PaymentWorkerListViewSet,
>>> PaymentDateListViewSet
>>> #from assessments.views import AssessmentViewSet
>>> from questions.views import QuestionViewSet
>>> 

Re: django models

2018-08-14 Thread Ramandeep Kaur
hi guys, i need your help
when i run makemigrations command,  i got error:
django.db.migrations.exceptions.NodeNotFoundError: Migration
task_types.0004_tasktype_training_kit dependencies reference nonexistent
parent node (u'training_kits', u'0003_auto_20160914_0722')

On Fri, Aug 10, 2018 at 8:21 PM Kasper Laudrup 
wrote:

> Hi Ramandeep,
>
> The problem is pretty much the same as before: Mismatched parentheses, but
> I'll leave to you to figure out where. It's pretty easy to spot.
>
> Did you find an editor that helps you syntax check python code?
>
> It'll make your life a lot easier.
>
> Kind regards,
>
> Kasper Laudrup
>
> On August 10, 2018 3:42:56 PM GMT+02:00, Ramandeep Kaur <
> hpramandeepkau...@gmail.com> wrote:
>>
>> thanks i got my  mistake but now again i am getting an error.
>> my urls.py:
>> from django.conf.urls import patterns, include, url
>> from django.contrib import admin
>> from django.views.generic import TemplateView
>>
>> from rest_framework_nested import routers
>>
>> from rest_auth.views import LogoutView
>>
>> from locations.views import LocationViewSet
>>
>> from tasks.views import TaskViewSet, BeneficiaryTasksView,
>> AssignedTasksView, CreatedTasksView, tasks_assign, tasks_smart_assign,
>> FilterTasksView, PaginatedTaskViewSet, get_tasks_length,
>> get_tasks_page_size, export_tasks_view, create_bulk_tasks,
>> import_data_view, get_filtered_tasks_length, PledgedTasksView,create_task
>> from task_types.views import TaskTypeViewSet
>> from task_status.views import TaskStatusViewSet
>> from feedback_types.views import FeedbackTypeViewSet
>> from organisations.views import OrganisationViewSet
>> from authentication.views import UserViewSet
>> from user_profiles.views import *
>> from forms.views import FormViewSet, FormDataViewSet, DataByFormView,
>> PersistentFormViewSet, PersistentFormDataView,export_filtered_form_data
>> from training_kits.views import *
>> from stages.views import StageViewSet
>> from notes.views import NoteViewSet, BeneficiaryNotesView,
>> CreatedNotesView
>> from user_messages.views import MessageViewSet, BeneficiaryMessagesView,
>> SentMessagesView
>> from todos.views import TodoViewSet, AssignedTodosView,
>> CreatedTodosView, BeneficiaryTodosView
>> from tags.views import (TagViewSet, LightTagViewSet, UserTagsView,
>> UserLightTagsView,
>> RemoveUserFromTag, RemoveExclusiveTagFromTag,
>> AddTagToUser, AddTagsToUser, AddExclusiveTagToTag)
>> from message_templates.views import MessageTemplateViewSet
>> #from calls.views import CallViewSet, BeneficiaryCallsView,
>> CallerCallsView
>> from task_status_categories.views import TaskStatusCategoryViewSet,
>> CreatedTaskStatusCategoriesView, getTaskCompletedFlagChoices
>> #from actions.views import get_action_classes, ActionViewSet
>> from events.views import EventViewSet
>> from event_conditions.views import EventConditionViewSet,
>> getEventConditionTypes, HelplineEventConditionsView,
>> NormalEventConditionsView
>> from hooks.views import HookViewSet
>> from ivrs.views import IVRViewSet, BeneficiaryIVRsView, SentIVRsView,
>> FeedbackIVRView
>> from ivr_templates.views import IVRTemplateViewSet
>> from exotel.views import MissedCall, ExotelViewSet, IncSMS, Lottery,
>> DostPaid, DostMother, DostFather
>> from guilds.views import GuildViewSet, add_users_to_guild
>> from notices.views import NoticeViewSet
>> from spaces.views import SpaceViewSet
>> from space_types.views import SpaceTypeViewSet, add_spaces
>> from interests.views import InterestViewSet, LightInterestViewSet,
>> AddInterestsToUser, RemoveInterestsFromUser, UserInterestsView
>> from pledges.views import PledgeViewSet, TaskPledgesView, UserPledgesView
>> from party_invitations.views import PartyInvitationViewSet,
>> SentPartyInvitationsView, ReceivedPartyInvitationsView
>> from task_comments.views import TaskCommentViewSet,
>> TaskCommentDetailedViewSet, TaskCommentsView, CommentedCommentsView
>> from follows.views import FollowViewSet, FollowerFollowsView,
>> FollowedFollowsView, get_follow
>> #from centers.views import CenterViewSet
>> from locations.views import LocationViewSet
>> from kits.views import KitViewSet
>> from parents.views import ParentViewSet,ParentWorkerListViewSet
>> from worker.views import WorkerViewSet
>> from child.views import ChildViewSet
>> from payments.views import
>> PaymentViewSet,PaymentWorkerListViewSet,PaymentDateListViewSet
>> #from assessments.views import AssessmentViewSet
>> from questions.views import QuestionViewSet
>> #from assessmentreports.views import AssessmentItemViewSet
>>
>> router = routers.SimpleRouter()
>>
>> #router.register(r'centers',CenterViewSet)
>> router.register(r'kits',KitViewSet)
>> router.register(r'parents',ParentViewSet)
>> router.register(r'workers',WorkerViewSet)
>> router.register(r'child',ChildViewSet)
>> #router.register(r'assessments',AssessmentViewSet)
>> router.register(r'questions',QuestionViewSet)
>> #router.register(r'assessmentitems',AssessmentItemViewSet)
>> 

Re: django models

2018-08-10 Thread Kasper Laudrup
Hi Ramandeep,

The problem is pretty much the same as before: Mismatched parentheses, but I'll 
leave to you to figure out where. It's pretty easy to spot.

Did you find an editor that helps you syntax check python code?

It'll make your life a lot easier.

Kind regards,

Kasper Laudrup

On August 10, 2018 3:42:56 PM GMT+02:00, Ramandeep Kaur 
 wrote:
>thanks i got my  mistake but now again i am getting an error.
>my urls.py:
>from django.conf.urls import patterns, include, url
>from django.contrib import admin
>from django.views.generic import TemplateView
>
>from rest_framework_nested import routers
>
>from rest_auth.views import LogoutView
>
>from locations.views import LocationViewSet
>
>from tasks.views import TaskViewSet, BeneficiaryTasksView,
>AssignedTasksView, CreatedTasksView, tasks_assign, tasks_smart_assign,
>FilterTasksView, PaginatedTaskViewSet, get_tasks_length,
>get_tasks_page_size, export_tasks_view, create_bulk_tasks,
>import_data_view, get_filtered_tasks_length,
>PledgedTasksView,create_task
>from task_types.views import TaskTypeViewSet
>from task_status.views import TaskStatusViewSet
>from feedback_types.views import FeedbackTypeViewSet
>from organisations.views import OrganisationViewSet
>from authentication.views import UserViewSet
>from user_profiles.views import *
>from forms.views import FormViewSet, FormDataViewSet, DataByFormView,
>PersistentFormViewSet, PersistentFormDataView,export_filtered_form_data
>from training_kits.views import *
>from stages.views import StageViewSet
>from notes.views import NoteViewSet, BeneficiaryNotesView,
>CreatedNotesView
>from user_messages.views import MessageViewSet,
>BeneficiaryMessagesView,
>SentMessagesView
>from todos.views import TodoViewSet, AssignedTodosView,
>CreatedTodosView,
>BeneficiaryTodosView
>from tags.views import (TagViewSet, LightTagViewSet, UserTagsView,
>UserLightTagsView,
>RemoveUserFromTag, RemoveExclusiveTagFromTag,
>AddTagToUser, AddTagsToUser, AddExclusiveTagToTag)
>from message_templates.views import MessageTemplateViewSet
>#from calls.views import CallViewSet, BeneficiaryCallsView,
>CallerCallsView
>from task_status_categories.views import TaskStatusCategoryViewSet,
>CreatedTaskStatusCategoriesView, getTaskCompletedFlagChoices
>#from actions.views import get_action_classes, ActionViewSet
>from events.views import EventViewSet
>from event_conditions.views import EventConditionViewSet,
>getEventConditionTypes, HelplineEventConditionsView,
>NormalEventConditionsView
>from hooks.views import HookViewSet
>from ivrs.views import IVRViewSet, BeneficiaryIVRsView, SentIVRsView,
>FeedbackIVRView
>from ivr_templates.views import IVRTemplateViewSet
>from exotel.views import MissedCall, ExotelViewSet, IncSMS, Lottery,
>DostPaid, DostMother, DostFather
>from guilds.views import GuildViewSet, add_users_to_guild
>from notices.views import NoticeViewSet
>from spaces.views import SpaceViewSet
>from space_types.views import SpaceTypeViewSet, add_spaces
>from interests.views import InterestViewSet, LightInterestViewSet,
>AddInterestsToUser, RemoveInterestsFromUser, UserInterestsView
>from pledges.views import PledgeViewSet, TaskPledgesView,
>UserPledgesView
>from party_invitations.views import PartyInvitationViewSet,
>SentPartyInvitationsView, ReceivedPartyInvitationsView
>from task_comments.views import TaskCommentViewSet,
>TaskCommentDetailedViewSet, TaskCommentsView, CommentedCommentsView
>from follows.views import FollowViewSet, FollowerFollowsView,
>FollowedFollowsView, get_follow
>#from centers.views import CenterViewSet
>from locations.views import LocationViewSet
>from kits.views import KitViewSet
>from parents.views import ParentViewSet,ParentWorkerListViewSet
>from worker.views import WorkerViewSet
>from child.views import ChildViewSet
>from payments.views import
>PaymentViewSet,PaymentWorkerListViewSet,PaymentDateListViewSet
>#from assessments.views import AssessmentViewSet
>from questions.views import QuestionViewSet
>#from assessmentreports.views import AssessmentItemViewSet
>
>router = routers.SimpleRouter()
>
>#router.register(r'centers',CenterViewSet)
>router.register(r'kits',KitViewSet)
>router.register(r'parents',ParentViewSet)
>router.register(r'workers',WorkerViewSet)
>router.register(r'child',ChildViewSet)
>#router.register(r'assessments',AssessmentViewSet)
>router.register(r'questions',QuestionViewSet)
>#router.register(r'assessmentitems',AssessmentItemViewSet)
>router.register(r'payments',PaymentViewSet)
>router.register(r'locations', LocationViewSet)
>router.register(r'tasks', TaskViewSet)
>router.register(r'task_types', TaskTypeViewSet)
>router.register(r'task_status', TaskStatusViewSet)
>router.register(r'feedback_types', FeedbackTypeViewSet)
>router.register(r'stages', StageViewSet)
>router.register(r'organisations', OrganisationViewSet)
>router.register(r'users_model', UserViewSet)
>router.register(r'users', UserDetailViewSet)
>router.register(r'forms', FormViewSet)
>router.register(r'forms-data', 

Re: django models

2018-08-10 Thread Ramandeep Kaur
thanks i got my  mistake but now again i am getting an error.
my urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.views.generic import TemplateView

from rest_framework_nested import routers

from rest_auth.views import LogoutView

from locations.views import LocationViewSet

from tasks.views import TaskViewSet, BeneficiaryTasksView,
AssignedTasksView, CreatedTasksView, tasks_assign, tasks_smart_assign,
FilterTasksView, PaginatedTaskViewSet, get_tasks_length,
get_tasks_page_size, export_tasks_view, create_bulk_tasks,
import_data_view, get_filtered_tasks_length, PledgedTasksView,create_task
from task_types.views import TaskTypeViewSet
from task_status.views import TaskStatusViewSet
from feedback_types.views import FeedbackTypeViewSet
from organisations.views import OrganisationViewSet
from authentication.views import UserViewSet
from user_profiles.views import *
from forms.views import FormViewSet, FormDataViewSet, DataByFormView,
PersistentFormViewSet, PersistentFormDataView,export_filtered_form_data
from training_kits.views import *
from stages.views import StageViewSet
from notes.views import NoteViewSet, BeneficiaryNotesView, CreatedNotesView
from user_messages.views import MessageViewSet, BeneficiaryMessagesView,
SentMessagesView
from todos.views import TodoViewSet, AssignedTodosView, CreatedTodosView,
BeneficiaryTodosView
from tags.views import (TagViewSet, LightTagViewSet, UserTagsView,
UserLightTagsView,
RemoveUserFromTag, RemoveExclusiveTagFromTag,
AddTagToUser, AddTagsToUser, AddExclusiveTagToTag)
from message_templates.views import MessageTemplateViewSet
#from calls.views import CallViewSet, BeneficiaryCallsView, CallerCallsView
from task_status_categories.views import TaskStatusCategoryViewSet,
CreatedTaskStatusCategoriesView, getTaskCompletedFlagChoices
#from actions.views import get_action_classes, ActionViewSet
from events.views import EventViewSet
from event_conditions.views import EventConditionViewSet,
getEventConditionTypes, HelplineEventConditionsView,
NormalEventConditionsView
from hooks.views import HookViewSet
from ivrs.views import IVRViewSet, BeneficiaryIVRsView, SentIVRsView,
FeedbackIVRView
from ivr_templates.views import IVRTemplateViewSet
from exotel.views import MissedCall, ExotelViewSet, IncSMS, Lottery,
DostPaid, DostMother, DostFather
from guilds.views import GuildViewSet, add_users_to_guild
from notices.views import NoticeViewSet
from spaces.views import SpaceViewSet
from space_types.views import SpaceTypeViewSet, add_spaces
from interests.views import InterestViewSet, LightInterestViewSet,
AddInterestsToUser, RemoveInterestsFromUser, UserInterestsView
from pledges.views import PledgeViewSet, TaskPledgesView, UserPledgesView
from party_invitations.views import PartyInvitationViewSet,
SentPartyInvitationsView, ReceivedPartyInvitationsView
from task_comments.views import TaskCommentViewSet,
TaskCommentDetailedViewSet, TaskCommentsView, CommentedCommentsView
from follows.views import FollowViewSet, FollowerFollowsView,
FollowedFollowsView, get_follow
#from centers.views import CenterViewSet
from locations.views import LocationViewSet
from kits.views import KitViewSet
from parents.views import ParentViewSet,ParentWorkerListViewSet
from worker.views import WorkerViewSet
from child.views import ChildViewSet
from payments.views import
PaymentViewSet,PaymentWorkerListViewSet,PaymentDateListViewSet
#from assessments.views import AssessmentViewSet
from questions.views import QuestionViewSet
#from assessmentreports.views import AssessmentItemViewSet

router = routers.SimpleRouter()

#router.register(r'centers',CenterViewSet)
router.register(r'kits',KitViewSet)
router.register(r'parents',ParentViewSet)
router.register(r'workers',WorkerViewSet)
router.register(r'child',ChildViewSet)
#router.register(r'assessments',AssessmentViewSet)
router.register(r'questions',QuestionViewSet)
#router.register(r'assessmentitems',AssessmentItemViewSet)
router.register(r'payments',PaymentViewSet)
router.register(r'locations', LocationViewSet)
router.register(r'tasks', TaskViewSet)
router.register(r'task_types', TaskTypeViewSet)
router.register(r'task_status', TaskStatusViewSet)
router.register(r'feedback_types', FeedbackTypeViewSet)
router.register(r'stages', StageViewSet)
router.register(r'organisations', OrganisationViewSet)
router.register(r'users_model', UserViewSet)
router.register(r'users', UserDetailViewSet)
router.register(r'forms', FormViewSet)
router.register(r'forms-data', FormDataViewSet)
router.register(r'trainingkits', TrainingKitViewSet)
router.register(r'trainingkitpages', TrainingKitPagesViewSet)
router.register(r'pages', PageViewSet)
router.register(r'notes', NoteViewSet)
router.register(r'messages', MessageViewSet)
router.register(r'todos', TodoViewSet)
router.register(r'tags', TagViewSet)
router.register(r'light_tags', LightTagViewSet)
router.register(r'message_templates', MessageTemplateViewSet)
#router.register(r'calls', 

Re: django models

2018-08-10 Thread Kasper Laudrup

Hi Ramandeep,
On 08/10/2018 07:36 AM, Ramandeep Kaur wrote:

> strange thing is that it indicates the error in line 395 which is in
> the end where i dont write any code.

It looks like your error is not closing the call to url() here:


url('^api/v1/calls/beneficiary/(?P\w+)/$',
# BeneficiaryCallsView.as_view(),
# name='beneficiary_calls'),
url('^api/v1/calls/caller/(?P\w+)/$',
# CallerCallsView.as_view(),
# name='caller_calls'),


The interpreter will try to look for the matching end ')' and give error 
out when it doesn't find that at the end of the file.


Errors like these can indeed be a bit hard to track down. Which editor 
are you using?


If you use an editor that understands Python, it can be quite a lot 
easier to debug these things in my experience or even avoid them in the 
first place.


I heard good things about pycharm, but I don't have any experience with 
that myself (I use emacs).


Don't know if that would have helped you here. Just a suggestion.

Kind regards,

Kasper Laudrup

--
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/556bdf45-8daf-4b4d-4657-de696b8e5d2f%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2018-08-09 Thread Mike Dewhirst
 db_tablespace or
settings.DEFAULT_INDEX_TABLESPACE
  File
"C:\Python27\lib\site-packages\django\conf\__init__.py",
line 55, in __getattr__
    self._setup(name)
  File
"C:\Python27\lib\site-packages\django\conf\__init__.py",
line 43, in _setup
    self._wrapped = Settings(settings_module)
  File
"C:\Python27\lib\site-packages\django\conf\__init__.py",
line 120, in __init__
    raise ImproperlyConfigured("The SECRET_KEY setting
must not be empty.")
django.core.exceptions.ImproperlyConfigured: The
SECRET_KEY setting must not be empty.

On Thu, Aug 9, 2018 at 11:13 AM, Mike Dewhirst
mailto:mi...@dewhirst.com.au>
<mailto:mi...@dewhirst.com.au
<mailto:mi...@dewhirst.com.au>>> wrote:

    On 9/08/2018 3:11 PM, Ramandeep Kaur wrote:

    i set the secret key but its again giving me the
same errror.
    django.core.exceptions.ImproperlyConfigured: The
SECRET_KEY
    setting must not be empty.


    Try running the migrations command with the settings
option so
    manage.py can find them.

    python manage.py makemigrations
--settings=



    On Wed, Aug 8, 2018 at 7:24 PM, Matthew Pava
    mailto:matthew.p...@iss.com>
<mailto:matthew.p...@iss.com
<mailto:matthew.p...@iss.com>>> wrote:

        Well, you could generate a SECRET KEY here:

https://www.miniwebtool.com/django-secret-key-generator/
<https://www.miniwebtool.com/django-secret-key-generator/>
       
<https://www.miniwebtool.com/django-secret-key-generator/
<https://www.miniwebtool.com/django-secret-key-generator/>>

        Then in your settings.py file you need to add
this line:

        SECRET_KEY = “[insert secret key here]”

https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
<https://docs.djangoproject.com/en/dev/ref/settings/#secret-key>
       
<https://docs.djangoproject.com/en/dev/ref/settings/#secret-key

<https://docs.djangoproject.com/en/dev/ref/settings/#secret-key>>

        *From:*django-users@googlegroups.com
<mailto:django-users@googlegroups.com>
        <mailto:django-users@googlegroups.com
<mailto:django-users@googlegroups.com>>
        [mailto:django-users@googlegroups.com
<mailto:django-users@googlegroups.com>
            <mailto:django-users@googlegroups.com
<mailto:django-users@googlegroups.com>>] *On Behalf Of
        *Ramandeep Kaur
        *Sent:* Wednesday, August 8, 2018 8:50 AM
        *To:* django-users@googlegroups.com
<mailto:django-users@googlegroups.com>
        <mailto:django-users@googlegroups.com
<mailto:django-users@googlegroups.com>>
        *Subject:* Re: django models

        I am new at Django so I don't know how to
create secret key.
        please explain me.

        On Wed, Aug 8, 2018, 1:20 PM Gerald Brown
      mailto:gsbrow...@gmail.com>
<mailto:gsbrow...@gmail.com
<mailto:gsbrow...@gmail.com>>> wrote:

            The last line of the error message tells
you what to do.
            Create a Secret Key in your settings.py
file because it
            says it is now empty.

            On Wednesday, 08 August, 2018 02:43 PM,
Ramandeep Kaur wrote:

                when i run this ./manage.py
makemigrations it gives
                some error. Don't know what to do.

                Traceback (most recent call last):

                  File "manage.py", line 10, in 

execute_from_command_line(sys.argv)

                  File

"C:\Python27\lib\site-packages\django\core\management\__init__.py",
                line 353, in execute_from_command_line

                    utility.execute()

                  File
   

Re: django models

2018-08-09 Thread Mike Dewhirst
    Try running the migrations command with the settings option so
    manage.py can find them.

    python manage.py makemigrations --settings=



    On Wed, Aug 8, 2018 at 7:24 PM, Matthew Pava
    mailto:matthew.p...@iss.com>
<mailto:matthew.p...@iss.com
<mailto:matthew.p...@iss.com>>> wrote:

        Well, you could generate a SECRET KEY here:

https://www.miniwebtool.com/django-secret-key-generator/
<https://www.miniwebtool.com/django-secret-key-generator/>
       
<https://www.miniwebtool.com/django-secret-key-generator/
<https://www.miniwebtool.com/django-secret-key-generator/>>

        Then in your settings.py file you need to add this
line:

        SECRET_KEY = “[insert secret key here]”

https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
<https://docs.djangoproject.com/en/dev/ref/settings/#secret-key>
       
<https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
<https://docs.djangoproject.com/en/dev/ref/settings/#secret-key>>

        *From:*django-users@googlegroups.com
<mailto:django-users@googlegroups.com>
        <mailto:django-users@googlegroups.com
<mailto:django-users@googlegroups.com>>
        [mailto:django-users@googlegroups.com
<mailto:django-users@googlegroups.com>
        <mailto:django-users@googlegroups.com
<mailto:django-users@googlegroups.com>>] *On Behalf Of
        *Ramandeep Kaur
        *Sent:* Wednesday, August 8, 2018 8:50 AM
        *To:* django-users@googlegroups.com
<mailto:django-users@googlegroups.com>
        <mailto:django-users@googlegroups.com
<mailto:django-users@googlegroups.com>>
        *Subject:* Re: django models

        I am new at Django so I don't know how to create
secret key.
        please explain me.

        On Wed, Aug 8, 2018, 1:20 PM Gerald Brown
        mailto:gsbrow...@gmail.com>
<mailto:gsbrow...@gmail.com <mailto:gsbrow...@gmail.com>>>
wrote:

            The last line of the error message tells you
what to do.
            Create a Secret Key in your settings.py file
because it
            says it is now empty.

            On Wednesday, 08 August, 2018 02:43 PM,
Ramandeep Kaur wrote:

                when i run this ./manage.py
makemigrations it gives
                some error. Don't know what to do.

                Traceback (most recent call last):

                  File "manage.py", line 10, in 

                    execute_from_command_line(sys.argv)

                  File
               
"C:\Python27\lib\site-packages\django\core\management\__init__.py",
                line 353, in execute_from_command_line

                    utility.execute()

                  File
               
"C:\Python27\lib\site-packages\django\core\management\__init__.py",
                line 345, in execute


               
self.fetch_command(subcommand).run_from_argv(self.argv)

                  File
               
"C:\Python27\lib\site-packages\django\core\management\__init__.py",
                line 195, in fetch_command

                    klass = load_command_class(app_name,
subcommand)

                  File
               
"C:\Python27\lib\site-packages\django\core\management\__init__.py",
                line 39, in load_command_class

                    module =
                import_module('%s.management.commands.%s' %
                (app_name, name))

                  File
"C:\Python27\lib\importlib\__init__.py", line
                37, in import_module

                    __import__(name)

                  File
               

"C:\Python27\lib\site-packages\django\core\management\commands\makemigrations.py",
                line 8, in 

                    from django.db.migrations.autodetector
import
                Migrati

Re: django models

2018-08-09 Thread Kasper Laudrup

Hi Ramandeep,

On 08/09/2018 09:57 AM, Ramandeep Kaur wrote:


hi kasper,this is my settings.py



What you have added to your settings.py doesn't make any sense. It is 
not valid Python code as your Python interpreter correctly tells you. I 
have no idea what you tried to achieve by writing that.


Read up on Python and modules here:

https://docs.python.org/3/tutorial/modules.html

Kind regards,

Kasper Laudrup

--
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/4a0710dc-e191-f4f2-659e-9038b9b0f49f%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2018-08-09 Thread Ramandeep Kaur
 import os
import sys

from django.core.exceptions import ImproperlyConfigured
from .base import *pip install django-generate-secret-key

def get_env_variable(var_name):
try:
return os.environ[var_name]
except KeyError:
error_msg = "Set the %s environment variable" % var_name
raise ImproperlyConfigured(error_msg)

BASE_DIR = os.path.dirname(os.path.dirname
(os.path.dirname(os.path.abspath(__file__

sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '{{ secret_key }}'



# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['52.220.91.39']

# Application definition

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'user_profiles.middleware.CustomCsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'vms2.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "static/templates"),
os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'vms2.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

# django-allauth settings

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)

ACCOUNT_USERNAME_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "none"
ACCOUNT_EMAIL_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = "username"
ACCOUNT_LOGIN_ATTEMPTS_LIMIT = None
ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = "/"
ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL =
"/user_details/edit/"
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True

# rest_auth settings

REST_AUTH_SERIALIZERS = {
'USER_DETAILS_SERIALIZER':
'user_profiles.serializers.UserSerializer'
}

REST_AUTH_REGISTER_SERIALIZERS = {
'REGISTER_SERIALIZER':
'authentication.serializers.UserRegisterSerializer'
}


# Email settings for gmail
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
# EMAIL_HOST_USER = get_env_variable('EMAIL_HOST_USER')
# EMAIL_HOST_PASSWORD = get_env_variable('EMAIL_HOST_PASSWORD')
# DEFAULT_FROM_EMAIL = get_env_variable('DEFAULT_FROM_EMAIL')

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


hi kasper,this is my settings.py


On Thu, Aug 9, 2018 at 1:11 PM, Kasper Laudrup 
wrote:

> Hi Ramandeep,
>
> On 08/09/2018 09:25 AM, Ramandeep Kaur wrote:
>
>> when i run my manage.py server its giving me invalid syntax error.
>>   File "C:\Users\Dell\vms2\vms2\settings\base.py", line 18
>> from .base import *pip install django-generate-secret-key
>>  ^
>> SyntaxError: invalid syntax
>>
>>
> What does your settings.py look like?
>
> Have you really written "from .base import *pip install
> django-generate-secret-key" in there?
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> 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/ms
> gid/django-users/000fb49c-8c46-9c67-1d2e-54e781795e17%40stacktrace.dk.
>
> 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 

Re: django models

2018-08-09 Thread Kasper Laudrup

Hi Ramandeep,

On 08/09/2018 09:25 AM, Ramandeep Kaur wrote:

when i run my manage.py server its giving me invalid syntax error.
  File "C:\Users\Dell\vms2\vms2\settings\base.py", line 18
    from .base import *pip install django-generate-secret-key
                         ^
SyntaxError: invalid syntax



What does your settings.py look like?

Have you really written "from .base import *pip install 
django-generate-secret-key" in there?


Kind regards,

Kasper Laudrup

--
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/000fb49c-8c46-9c67-1d2e-54e781795e17%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2018-08-09 Thread Ramandeep Kaur
t;> line 39, in load_command_class
>> module = import_module('%s.management.commands.%s' % (app_name,
>> name))
>>   File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
>> __import__(name)
>>   File 
>> "C:\Python27\lib\site-packages\django\core\management\commands\makemigrations.py",
>> line 8, in 
>> from django.db.migrations.autodetector import MigrationAutodetector
>>   File "C:\Python27\lib\site-packages\django\db\migrations\autodetector.py",
>> line 13, in 
>> from django.db.migrations.questioner import MigrationQuestioner
>>   File "C:\Python27\lib\site-packages\django\db\migrations\questioner.py",
>> line 12, in 
>> from .loader import MigrationLoader
>>   File "C:\Python27\lib\site-packages\django\db\migrations\loader.py",
>> line 10, in 
>> from django.db.migrations.recorder import MigrationRecorder
>>   File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
>> line 12, in 
>> class MigrationRecorder(object):
>>   File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
>> line 26, in MigrationRecorder
>> class Migration(models.Model):
>>   File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
>> line 27, in Migration
>> app = models.CharField(max_length=255)
>>   File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py",
>> line 1072, in __init__
>> super(CharField, self).__init__(*args, **kwargs)
>>   File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py",
>> line 166, in __init__
>> self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESP
>> ACE
>>   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 55,
>> in __getattr__
>> self._setup(name)
>>   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 43,
>> in _setup
>> self._wrapped = Settings(settings_module)
>>   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line
>> 120, in __init__
>> raise ImproperlyConfigured("The SECRET_KEY setting must not be
>> empty.")
>> django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must
>> not be empty.
>>
>> On Thu, Aug 9, 2018 at 11:13 AM, Mike Dewhirst > <mailto:mi...@dewhirst.com.au>> wrote:
>>
>> On 9/08/2018 3:11 PM, Ramandeep Kaur wrote:
>>
>>> i set the secret key but its again giving me the same errror.
>>> django.core.exceptions.ImproperlyConfigured: The SECRET_KEY
>>>     setting must not be empty.
>>>
>>
>> Try running the migrations command with the settings option so
>> manage.py can find them.
>>
>> python manage.py makemigrations --settings=
>>
>>
>>
>>> On Wed, Aug 8, 2018 at 7:24 PM, Matthew Pava
>>> mailto:matthew.p...@iss.com>> wrote:
>>>
>>> Well, you could generate a SECRET KEY here:
>>>
>>> https://www.miniwebtool.com/django-secret-key-generator/
>>> <https://www.miniwebtool.com/django-secret-key-generator/>
>>>
>>> Then in your settings.py file you need to add this line:
>>>
>>> SECRET_KEY = “[insert secret key here]”
>>>
>>> https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
>>> <https://docs.djangoproject.com/en/dev/ref/settings/#secret-key>
>>>
>>> *From:*django-users@googlegroups.com
>>> <mailto:django-users@googlegroups.com>
>>> [mailto:django-users@googlegroups.com
>>> <mailto:django-users@googlegroups.com>] *On Behalf Of
>>> *Ramandeep Kaur
>>> *Sent:* Wednesday, August 8, 2018 8:50 AM
>>> *To:* django-users@googlegroups.com
>>> <mailto:django-users@googlegroups.com>
>>> *Subject:* Re: django models
>>>
>>> I am new at Django so I don't know how to create secret key.
>>> please explain me.
>>>
>>> On Wed, Aug 8, 2018, 1:20 PM Gerald Brown
>>> mailto:gsbrow...@gmail.com>> wrote:
>>>
>>> The last line of the error message tells you what to do.
>>> Create a Secret Key in your settings.py file because it
>>> says it is now empty.
>>>
>>>

Re: django models

2018-08-09 Thread Mike Dewhirst
igrationRecorder(object):
  File 
"C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 
26, in MigrationRecorder

    class Migration(models.Model):
  File 
"C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 
27, in Migration

    app = models.CharField(max_length=255)
  File 
"C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", 
line 1072, in __init__

    super(CharField, self).__init__(*args, **kwargs)
  File 
"C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", 
line 166, in __init__
    self.db_tablespace = db_tablespace or 
settings.DEFAULT_INDEX_TABLESPACE
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 
55, in __getattr__

    self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 
43, in _setup

    self._wrapped = Settings(settings_module)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 
120, in __init__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be 
empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting 
must not be empty.


On Thu, Aug 9, 2018 at 11:13 AM, Mike Dewhirst <mailto:mi...@dewhirst.com.au>> wrote:


On 9/08/2018 3:11 PM, Ramandeep Kaur wrote:

i set the secret key but its again giving me the same errror.
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY
setting must not be empty.


Try running the migrations command with the settings option so
manage.py can find them.

python manage.py makemigrations --settings=




On Wed, Aug 8, 2018 at 7:24 PM, Matthew Pava
mailto:matthew.p...@iss.com>> wrote:

Well, you could generate a SECRET KEY here:

https://www.miniwebtool.com/django-secret-key-generator/
<https://www.miniwebtool.com/django-secret-key-generator/>

Then in your settings.py file you need to add this line:

SECRET_KEY = “[insert secret key here]”

https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
<https://docs.djangoproject.com/en/dev/ref/settings/#secret-key>

*From:*django-users@googlegroups.com
<mailto:django-users@googlegroups.com>
[mailto:django-users@googlegroups.com
<mailto:django-users@googlegroups.com>] *On Behalf Of
*Ramandeep Kaur
*Sent:* Wednesday, August 8, 2018 8:50 AM
*To:* django-users@googlegroups.com
<mailto:django-users@googlegroups.com>
*Subject:* Re: django models

I am new at Django so I don't know how to create secret key.
please explain me.

On Wed, Aug 8, 2018, 1:20 PM Gerald Brown
mailto:gsbrow...@gmail.com>> wrote:

The last line of the error message tells you what to do.
Create a Secret Key in your settings.py file because it
says it is now empty.

On Wednesday, 08 August, 2018 02:43 PM, Ramandeep Kaur wrote:

when i run this ./manage.py makemigrations it gives
some error. Don't know what to do.

Traceback (most recent call last):

  File "manage.py", line 10, in 

    execute_from_command_line(sys.argv)

  File

"C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 353, in execute_from_command_line

    utility.execute()

  File

"C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 345, in execute

   
self.fetch_command(subcommand).run_from_argv(self.argv)

  File

"C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 195, in fetch_command

    klass = load_command_class(app_name, subcommand)

  File

"C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 39, in load_command_class

    module =
import_module('%s.management.commands.%s' %
(app_name, name))

  File "C:\Python27\lib\importlib\__init__.py", line
37, in import_module

    __import__(name)

  File

"C:\Python27\lib\site-packages\django\core\management\commands\makemigrations.py",
line 8, in 

    from django.db.migrations.autodetector import
MigrationAutodetector

  File

"C:\Python27\lib\site-packages\django\db\migrations\autodetector.py",
line 13, in 

    from django.db.migrations.questioner import
 

Re: django models

2018-08-08 Thread Ramandeep Kaur
i set the secret key but its again giving me the same errror.
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must
not be empty.

On Wed, Aug 8, 2018 at 7:24 PM, Matthew Pava  wrote:

> Well, you could generate a SECRET KEY here:
>
> https://www.miniwebtool.com/django-secret-key-generator/
>
>
>
> Then in your settings.py file you need to add this line:
>
> SECRET_KEY = “[insert secret key here]”
>
>
>
> https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
>
>
>
>
>
> *From:* django-users@googlegroups.com [mailto:django-users@
> googlegroups.com] *On Behalf Of *Ramandeep Kaur
> *Sent:* Wednesday, August 8, 2018 8:50 AM
> *To:* django-users@googlegroups.com
> *Subject:* Re: django models
>
>
>
> I am new at Django so I don't know how to create secret key. please
> explain me.
>
>
>
> On Wed, Aug 8, 2018, 1:20 PM Gerald Brown  wrote:
>
> The last line of the error message tells you what to do.  Create a Secret
> Key in your settings.py file because it says it is now empty.
>
>
>
> On Wednesday, 08 August, 2018 02:43 PM, Ramandeep Kaur wrote:
>
> when i run this ./manage.py makemigrations it gives some error. Don't
> know what to do.
>
>
>
> Traceback (most recent call last):
>
>   File "manage.py", line 10, in 
>
> execute_from_command_line(sys.argv)
>
>   File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 353, in execute_from_command_line
>
> utility.execute()
>
>   File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 345, in execute
>
> self.fetch_command(subcommand).run_from_argv(self.argv)
>
>   File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 195, in fetch_command
>
> klass = load_command_class(app_name, subcommand)
>
>   File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 39, in load_command_class
>
> module = import_module('%s.management.commands.%s' % (app_name, name))
>
>   File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
>
> __import__(name)
>
>   File 
> "C:\Python27\lib\site-packages\django\core\management\commands\makemigrations.py",
> line 8, in 
>
> from django.db.migrations.autodetector import MigrationAutodetector
>
>   File "C:\Python27\lib\site-packages\django\db\migrations\autodetector.py",
> line 13, in 
>
> from django.db.migrations.questioner import MigrationQuestioner
>
>   File "C:\Python27\lib\site-packages\django\db\migrations\questioner.py",
> line 12, in 
>
> from .loader import MigrationLoader
>
>   File "C:\Python27\lib\site-packages\django\db\migrations\loader.py",
> line 10, in 
>
> from django.db.migrations.recorder import MigrationRecorder
>
>   File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
> line 12, in 
>
> class MigrationRecorder(object):
>
>   File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
> line 26, in MigrationRecorder
>
> class Migration(models.Model):
>
>   File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
> line 27, in Migration
>
> app = models.CharField(max_length=255)
>
>   File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py",
> line 1072, in __init__
>
> super(CharField, self).__init__(*args, **kwargs)
>
>   File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py",
> line 166, in __init__
>
> self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_
> TABLESPACE
>
>   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 55,
> in __getattr__
>
> self._setup(name)
>
>   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 43,
> in _setup
>
> self._wrapped = Settings(settings_module)
>
>   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 120,
> in __init__
>
> raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
>
> django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must
> not be empty.
>
>
>
> On Wed, Aug 8, 2018 at 6:22 AM, Gerald Brown  wrote:
>
> Just delete the code in models.py and run ./manage.py makemigrations and
> ./manage.py migrate.
>
>
>
> On Wednesday, 08 August, 2018 01:14 AM, Ramandeep Kaur wrote:
>
> My question is that how to delete models in django?
>
> --
> You received this me

RE: django models

2018-08-08 Thread Matthew Pava
Well, you could generate a SECRET KEY here:
https://www.miniwebtool.com/django-secret-key-generator/

Then in your settings.py file you need to add this line:
SECRET_KEY = “[insert secret key here]”

https://docs.djangoproject.com/en/dev/ref/settings/#secret-key


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Ramandeep Kaur
Sent: Wednesday, August 8, 2018 8:50 AM
To: django-users@googlegroups.com
Subject: Re: django models

I am new at Django so I don't know how to create secret key. please explain me.

On Wed, Aug 8, 2018, 1:20 PM Gerald Brown 
mailto:gsbrow...@gmail.com>> wrote:

The last line of the error message tells you what to do.  Create a Secret Key 
in your settings.py file because it says it is now empty.

On Wednesday, 08 August, 2018 02:43 PM, Ramandeep Kaur wrote:
when i run this ./manage.py makemigrations it gives some error. Don't know what 
to do.

Traceback (most recent call last):
  File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 
353, in execute_from_command_line
utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 
345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 
195, in fetch_command
klass = load_command_class(app_name, subcommand)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 
39, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
  File 
"C:\Python27\lib\site-packages\django\core\management\commands\makemigrations.py",
 line 8, in 
from django.db.migrations.autodetector import MigrationAutodetector
  File "C:\Python27\lib\site-packages\django\db\migrations\autodetector.py", 
line 13, in 
from django.db.migrations.questioner import MigrationQuestioner
  File "C:\Python27\lib\site-packages\django\db\migrations\questioner.py", line 
12, in 
from .loader import MigrationLoader
  File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 10, 
in 
from django.db.migrations.recorder import MigrationRecorder
  File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 
12, in 
class MigrationRecorder(object):
  File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 
26, in MigrationRecorder
class Migration(models.Model):
  File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 
27, in Migration
app = models.CharField(max_length=255)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", 
line 1072, in __init__
super(CharField, self).__init__(*args, **kwargs)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", 
line 166, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 55, in 
__getattr__
self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 43, in 
_setup
self._wrapped = Settings(settings_module)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 120, in 
__init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be 
empty.

On Wed, Aug 8, 2018 at 6:22 AM, Gerald Brown 
mailto:gsbrow...@gmail.com>> wrote:

Just delete the code in models.py and run ./manage.py makemigrations and 
./manage.py migrate.

On Wednesday, 08 August, 2018 01:14 AM, Ramandeep Kaur wrote:
My question is that how to delete models in django?
--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto: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/42e646fa-af94-4250-b04a-5765e2975c3e%40googlegroups.com<https://groups.google.com/d/msgid/django-users/42e646fa-af94-4250-b04a-5765e2975c3e%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
&qu

Re: django models

2018-08-08 Thread Ramandeep Kaur
I am new at Django so I don't know how to create secret key. please explain
me.

On Wed, Aug 8, 2018, 1:20 PM Gerald Brown  wrote:

> The last line of the error message tells you what to do.  Create a Secret
> Key in your settings.py file because it says it is now empty.
>
> On Wednesday, 08 August, 2018 02:43 PM, Ramandeep Kaur wrote:
>
> when i run this ./manage.py makemigrations it gives some error. Don't
> know what to do.
>
> Traceback (most recent call last):
>   File "manage.py", line 10, in 
> execute_from_command_line(sys.argv)
>   File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 353, in execute_from_command_line
> utility.execute()
>   File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 345, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 195, in fetch_command
> klass = load_command_class(app_name, subcommand)
>   File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 39, in load_command_class
> module = import_module('%s.management.commands.%s' % (app_name, name))
>   File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
> __import__(name)
>   File
> "C:\Python27\lib\site-packages\django\core\management\commands\makemigrations.py",
> line 8, in 
> from django.db.migrations.autodetector import MigrationAutodetector
>   File
> "C:\Python27\lib\site-packages\django\db\migrations\autodetector.py", line
> 13, in 
> from django.db.migrations.questioner import MigrationQuestioner
>   File "C:\Python27\lib\site-packages\django\db\migrations\questioner.py",
> line 12, in 
> from .loader import MigrationLoader
>   File "C:\Python27\lib\site-packages\django\db\migrations\loader.py",
> line 10, in 
> from django.db.migrations.recorder import MigrationRecorder
>   File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
> line 12, in 
> class MigrationRecorder(object):
>   File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
> line 26, in MigrationRecorder
> class Migration(models.Model):
>   File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
> line 27, in Migration
> app = models.CharField(max_length=255)
>   File
> "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line
> 1072, in __init__
> super(CharField, self).__init__(*args, **kwargs)
>   File
> "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line
> 166, in __init__
> self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
>   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 55,
> in __getattr__
> self._setup(name)
>   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 43,
> in _setup
> self._wrapped = Settings(settings_module)
>   File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 120,
> in __init__
> raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
> django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must
> not be empty.
>
> On Wed, Aug 8, 2018 at 6:22 AM, Gerald Brown  wrote:
>
>> Just delete the code in models.py and run ./manage.py makemigrations and
>> ./manage.py migrate.
>>
>> On Wednesday, 08 August, 2018 01:14 AM, Ramandeep Kaur wrote:
>>
>> My question is that how to delete models in django?
>> --
>> 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/42e646fa-af94-4250-b04a-5765e2975c3e%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/ebb428c7-b1cd-46e2-e139-9fe96a884353%40gmail.com
>> .
>>
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message 

Re: django models

2018-08-08 Thread Balasriharsha Cheeday
You must have removed the secret key in settings.py file, try re-adding 
that secret key, then it should work just fine

On Tuesday, August 7, 2018 at 10:17:00 AM UTC-7, Ramandeep Kaur wrote:
>
> My question is that how to delete models in django?
>

-- 
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/cb8e793b-c45f-487f-93d8-e8fa271302e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2018-08-08 Thread Gerald Brown
The last line of the error message tells you what to do.  Create a 
Secret Key in your settings.py file because it says it is now empty.



On Wednesday, 08 August, 2018 02:43 PM, Ramandeep Kaur wrote:
when i run this ./manage.py makemigrations it gives some error. Don't 
know what to do.


Traceback (most recent call last):
  File "manage.py", line 10, in 
    execute_from_command_line(sys.argv)
  File 
"C:\Python27\lib\site-packages\django\core\management\__init__.py", 
line 353, in execute_from_command_line

    utility.execute()
  File 
"C:\Python27\lib\site-packages\django\core\management\__init__.py", 
line 345, in execute

self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"C:\Python27\lib\site-packages\django\core\management\__init__.py", 
line 195, in fetch_command

    klass = load_command_class(app_name, subcommand)
  File 
"C:\Python27\lib\site-packages\django\core\management\__init__.py", 
line 39, in load_command_class

    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File 
"C:\Python27\lib\site-packages\django\core\management\commands\makemigrations.py", 
line 8, in 

    from django.db.migrations.autodetector import MigrationAutodetector
  File 
"C:\Python27\lib\site-packages\django\db\migrations\autodetector.py", 
line 13, in 

    from django.db.migrations.questioner import MigrationQuestioner
  File 
"C:\Python27\lib\site-packages\django\db\migrations\questioner.py", 
line 12, in 

    from .loader import MigrationLoader
  File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", 
line 10, in 

    from django.db.migrations.recorder import MigrationRecorder
  File 
"C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 
12, in 

    class MigrationRecorder(object):
  File 
"C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 
26, in MigrationRecorder

    class Migration(models.Model):
  File 
"C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 
27, in Migration

    app = models.CharField(max_length=255)
  File 
"C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", 
line 1072, in __init__

    super(CharField, self).__init__(*args, **kwargs)
  File 
"C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", 
line 166, in __init__
    self.db_tablespace = db_tablespace or 
settings.DEFAULT_INDEX_TABLESPACE
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 
55, in __getattr__

    self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 
43, in _setup

    self._wrapped = Settings(settings_module)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 
120, in __init__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be 
empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting 
must not be empty.


On Wed, Aug 8, 2018 at 6:22 AM, Gerald Brown > wrote:


Just delete the code in models.py and run ./manage.py
makemigrations and ./manage.py migrate.


On Wednesday, 08 August, 2018 01:14 AM, Ramandeep Kaur wrote:

My question is that how to delete models in django?
-- 
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/42e646fa-af94-4250-b04a-5765e2975c3e%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/ebb428c7-b1cd-46e2-e139-9fe96a884353%40gmail.com


Re: django models

2018-08-08 Thread Ramandeep Kaur
when i run this ./manage.py makemigrations it gives some error. Don't know
what to do.

Traceback (most recent call last):
  File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 353, in execute_from_command_line
utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 195, in fetch_command
klass = load_command_class(app_name, subcommand)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 39, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
  File
"C:\Python27\lib\site-packages\django\core\management\commands\makemigrations.py",
line 8, in 
from django.db.migrations.autodetector import MigrationAutodetector
  File
"C:\Python27\lib\site-packages\django\db\migrations\autodetector.py", line
13, in 
from django.db.migrations.questioner import MigrationQuestioner
  File "C:\Python27\lib\site-packages\django\db\migrations\questioner.py",
line 12, in 
from .loader import MigrationLoader
  File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line
10, in 
from django.db.migrations.recorder import MigrationRecorder
  File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
line 12, in 
class MigrationRecorder(object):
  File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
line 26, in MigrationRecorder
class Migration(models.Model):
  File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py",
line 27, in Migration
app = models.CharField(max_length=255)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py",
line 1072, in __init__
super(CharField, self).__init__(*args, **kwargs)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py",
line 166, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 55, in
__getattr__
self._setup(name)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 43, in
_setup
self._wrapped = Settings(settings_module)
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 120,
in __init__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must
not be empty.

On Wed, Aug 8, 2018 at 6:22 AM, Gerald Brown  wrote:

> Just delete the code in models.py and run ./manage.py makemigrations and
> ./manage.py migrate.
>
> On Wednesday, 08 August, 2018 01:14 AM, Ramandeep Kaur wrote:
>
> My question is that how to delete models in django?
> --
> 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/42e646fa-af94-4250-b04a-5765e2975c3e%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/ebb428c7-b1cd-46e2-e139-9fe96a884353%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/CAL18nxmkKT9JPrvxnzQ3n1hs-KXXEUzBSX0YYqr-PP69K_PPJw%40mail.gmail.com.
For more 

Re: django models

2018-08-07 Thread Gerald Brown
Just delete the code in models.py and run ./manage.py makemigrations and 
./manage.py migrate.



On Wednesday, 08 August, 2018 01:14 AM, Ramandeep Kaur wrote:

My question is that how to delete models in django?
--
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/42e646fa-af94-4250-b04a-5765e2975c3e%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/ebb428c7-b1cd-46e2-e139-9fe96a884353%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2018-08-07 Thread Christophe Pettus


> On Aug 7, 2018, at 10:14, Ramandeep Kaur  wrote:
> 
> My question is that how to delete models in django?

Do you need to delete a model *class*, or a model *instance*?

--
-- Christophe Pettus
   x...@thebuild.com

-- 
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/6F27F93D-AD7C-4ACD-99A0-D940DF1BC87E%40thebuild.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Models

2016-05-27 Thread Ken Edem
Wow, Derek what a great link. Thanks very much.

Ken

On Friday, May 27, 2016 at 4:47:56 PM UTC+2, Derek wrote:
>
> There a number of designs for similar situations online; a quick Google 
> showed me:
>
> * http://www.databasedev.co.uk/student_courses_data_model.html
> * http://databaseanswers.org/data_models/ 
>
> And I am sure there are more... 
>
> If this is your first project. I would not be too fussed about making it 
> perfect.  Try out what seems to work and then iterate as you go.  You'll 
> learn a lot and probably end up having to rewrite based on all your 
> learning.
>
> On Friday, 27 May 2016 02:47:34 UTC+2, Ken Edem wrote:
>>
>> I am new to Django Python and I need bit of help
>>
>>
>>
>> Can someone please help me with how I should structure my models, since 
>> this is a very important part of the project I am trying to develop, I had 
>> been teaching myself and not yet good at this stuff. I want to develop a 
>> web project for matching teachers or instructors who will teach students 
>> who subscribes to our service at they residence.For now I think I will need 
>> these models:
>>
>>
>> Students = Database to contain all students details.  See below for the 
>> database fields
>>
>> Instructors = Database to contain all instructors or teachers details. 
>> See below
>>
>> Course = Databases for all the courses or services that will be offering
>>
>> Feedbacks = Database to contains both feedbacks from students about 
>> teachers and also teachers about students.
>>
>>
>> So, I have done something in terms of normalising my database, but I do 
>> not think it is efficient enough.? I think I also need a database Class, 
>> which is combination of Students and Instructors, but I cannot figures what 
>> the fields of this database should be.
>>
>> I also think I need a combine database Instructors & Course and Course & 
>> Students. But I cannot figure out what the fields of these databases also 
>> should be and what the foreign key or whatever should be.
>>
>>
>> You see, our primary service will be matching students with instructors 
>> and having these instructors teach student what they want to be thought.
>>
>>
>> Please can  someone assist me in structuring my models a structure and 
>> also should I just have one app or separate apps for students, instructors, 
>> feedbacks etc. Thanks in advance.
>>
>>
>> Below is my database models.
>>
>>
>> Thanks agains
>>
>>
>>  
>>
>>
>> Models and Tables
>>
>> -   Students
>>
>> -   Instructors
>>
>> -   Course
>>
>> -   Feedbacks
>>
>> -   Class
>>
>>
>> Model Properties and Fields
>>
>> Students
>>
>> -   student-id
>>
>> -   student_firstname
>>
>> -   student_lastname
>>
>> -   student_address
>>
>> -   student_city
>>
>> -   student_region
>>
>> -   student_startdate  (immediately, in 2 weeks, in a month over 6 months)
>>
>> -   student_classLocation (student address, instructor address, arrange 
>> location)
>>
>> -   student_phone1
>>
>> -   student_email
>>
>> -   student_phone2
>>
>> -   student_internetContact  (skype, viber etc)
>>
>> -   student_days_to_take_classes (mon - sun)
>>
>> -   student_duration_of_course  (1 - 12 months)
>>
>> -   student_hours_to_spend_on_course  (1 -8 hours)
>>
>> -   student_class_start_time  ( 06am - 06am)
>>
>> -   student_course_skill_level (beginner, intermediate, advance)
>>
>> -   student_personal_wishes_to_help_match_an_intructor ( )
>>
>> -   student_budget_amount
>>
>> -   student_preferred_instructor_gender  (male, female)
>>
>> -   student_date_of_birth
>>
>>
>> Students Methods and actions
>>
>> -   match a student to instructors
>>
>> -   seek payment
>>
>> -   message update
>>
>>
>>
>>
>> Instuctors
>>
>> -   id
>>
>> -   firstname
>>
>> -   lastname
>>
>> -   middlename
>>
>> -   gender
>>
>> -   date_of_birth
>>
>> -   phone1
>>
>> -   phone2
>>
>> -   streetaddress
>>
>> -   city
>>
>> -   region
>>
>> -   country
>>
>> -   qualifications  (multiple entry)
>>
>> -   certfications  (multiple entry)
>>
>> -   degrees (multiple entry)
>>
>> -   present occupation
>>
>> -   previous occupations (multiple entry)
>>
>> -   present job position
>>
>> -   length of teaching skills
>>
>> -   type of skills to teach
>>
>> -   class location (student address, tutor address, arranged address)
>>
>>
>> Instructor Methods and Actions
>>
>> match instructor to students
>>
>> seek instructors
>>
>> pay instructors
>>
>> -
>>
>>
>>
>> Courses
>>
>> -   id
>>
>> -   course_name
>>
>> -   course_description
>>
>> -   course_duration
>>
>>
>> Methods
>>
>>
>>
>> Feedbacks
>>
>> -   id
>>
>> -   course_name
>>
>> -   instructor
>>
>> -   student
>>
>> -   Feedback_details
>>
>> -   Grade (Beneficial, Great, Average, Satisfied, Very Satisfied, 
>> Excellent)
>>
>>
>>
>>
>> Class
>>
>> -   instructor
>>
>> -   students
>>
>> -   course
>>
>

-- 
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 

Re: Django Models

2016-05-27 Thread Derek
There a number of designs for similar situations online; a quick Google 
showed me:

* http://www.databasedev.co.uk/student_courses_data_model.html
* http://databaseanswers.org/data_models/ 

And I am sure there are more... 

If this is your first project. I would not be too fussed about making it 
perfect.  Try out what seems to work and then iterate as you go.  You'll 
learn a lot and probably end up having to rewrite based on all your 
learning.

On Friday, 27 May 2016 02:47:34 UTC+2, Ken Edem wrote:
>
> I am new to Django Python and I need bit of help
>
>
>
> Can someone please help me with how I should structure my models, since 
> this is a very important part of the project I am trying to develop, I had 
> been teaching myself and not yet good at this stuff. I want to develop a 
> web project for matching teachers or instructors who will teach students 
> who subscribes to our service at they residence.For now I think I will need 
> these models:
>
>
> Students = Database to contain all students details.  See below for the 
> database fields
>
> Instructors = Database to contain all instructors or teachers details. See 
> below
>
> Course = Databases for all the courses or services that will be offering
>
> Feedbacks = Database to contains both feedbacks from students about 
> teachers and also teachers about students.
>
>
> So, I have done something in terms of normalising my database, but I do 
> not think it is efficient enough.? I think I also need a database Class, 
> which is combination of Students and Instructors, but I cannot figures what 
> the fields of this database should be.
>
> I also think I need a combine database Instructors & Course and Course & 
> Students. But I cannot figure out what the fields of these databases also 
> should be and what the foreign key or whatever should be.
>
>
> You see, our primary service will be matching students with instructors 
> and having these instructors teach student what they want to be thought.
>
>
> Please can  someone assist me in structuring my models a structure and 
> also should I just have one app or separate apps for students, instructors, 
> feedbacks etc. Thanks in advance.
>
>
> Below is my database models.
>
>
> Thanks agains
>
>
>  
>
>
> Models and Tables
>
> -   Students
>
> -   Instructors
>
> -   Course
>
> -   Feedbacks
>
> -   Class
>
>
> Model Properties and Fields
>
> Students
>
> -   student-id
>
> -   student_firstname
>
> -   student_lastname
>
> -   student_address
>
> -   student_city
>
> -   student_region
>
> -   student_startdate  (immediately, in 2 weeks, in a month over 6 months)
>
> -   student_classLocation (student address, instructor address, arrange 
> location)
>
> -   student_phone1
>
> -   student_email
>
> -   student_phone2
>
> -   student_internetContact  (skype, viber etc)
>
> -   student_days_to_take_classes (mon - sun)
>
> -   student_duration_of_course  (1 - 12 months)
>
> -   student_hours_to_spend_on_course  (1 -8 hours)
>
> -   student_class_start_time  ( 06am - 06am)
>
> -   student_course_skill_level (beginner, intermediate, advance)
>
> -   student_personal_wishes_to_help_match_an_intructor ( )
>
> -   student_budget_amount
>
> -   student_preferred_instructor_gender  (male, female)
>
> -   student_date_of_birth
>
>
> Students Methods and actions
>
> -   match a student to instructors
>
> -   seek payment
>
> -   message update
>
>
>
>
> Instuctors
>
> -   id
>
> -   firstname
>
> -   lastname
>
> -   middlename
>
> -   gender
>
> -   date_of_birth
>
> -   phone1
>
> -   phone2
>
> -   streetaddress
>
> -   city
>
> -   region
>
> -   country
>
> -   qualifications  (multiple entry)
>
> -   certfications  (multiple entry)
>
> -   degrees (multiple entry)
>
> -   present occupation
>
> -   previous occupations (multiple entry)
>
> -   present job position
>
> -   length of teaching skills
>
> -   type of skills to teach
>
> -   class location (student address, tutor address, arranged address)
>
>
> Instructor Methods and Actions
>
> match instructor to students
>
> seek instructors
>
> pay instructors
>
> -
>
>
>
> Courses
>
> -   id
>
> -   course_name
>
> -   course_description
>
> -   course_duration
>
>
> Methods
>
>
>
> Feedbacks
>
> -   id
>
> -   course_name
>
> -   instructor
>
> -   student
>
> -   Feedback_details
>
> -   Grade (Beneficial, Great, Average, Satisfied, Very Satisfied, 
> Excellent)
>
>
>
>
> Class
>
> -   instructor
>
> -   students
>
> -   course
>

-- 
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/4bffe8b3-632f-428d-a5a1-d1b406278876%40googlegroups.com.
For more options, 

Re: Django Models

2016-05-06 Thread Sergiy Khohlov
 simplest way is using  filter() against all()
Take a look at
https://docs.djangoproject.com/en/1.9/ref/models/querysets/

Many thanks,

Serge


+380 636150445
skype: skhohlov

On Fri, May 6, 2016 at 5:27 PM, Omar  wrote:

> Gretting, I have in my DataBase (Directorios) two row, Departamento and
> Telefonos with the method Directorios.objects.all() I can get all objects
> in my DB but I need just get all Departamento in a variable, I don’t know
> how get it separated.
>
> --
> 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/001a01d1a7a3%246b23ef40%24416bcdc0%24%40infomed.sld.cu
> 
> .
> 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/CADTRxJNVNQE-M-Agy9Ca3iJyA5fTBeOU%3DetV9K7dd%2BzhhMVG1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django models choices

2016-03-21 Thread Mike Dewhirst

On 21/03/2016 7:29 PM, Amine Yaiche wrote:

Hi everyone,

Given a field in a model that uses choices:

|
CHOICES =(
   (0,"choice_0"),
   (1,"choice_1")
)

foo =models.IntegerField(choices=CHOICES)
|


If i put a value other than 0 or 1, django will accept it. Is that
possible that we instruct Django to accept only values that are
mentioned in CHOICES without creating a validator function.


Why don't you want to validate in the model?

I find it valuable to put all sorts of validators in the clean() method 
and raise a ValidationError to force the user to enter good data. eg.,


if self.foo not in CHOICES:
raise ValidationError("bad foo")

Unless there are special reasons otherwise, I think it is much better in 
the model than the form.


Mike




--
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/78d84aa0-506f-4d5c-9590-ef6325c255e0%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/56F0891E.9060500%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Django models choices

2016-03-21 Thread Amandeep Singh
The choices don't enforce any default validation. But if you are populating
the data from a http call then use ModelForm they show the invalid_choice
error message on entering value other than defined choices

On Mon, Mar 21, 2016 at 1:59 PM, Amine Yaiche  wrote:

> Hi everyone,
>
> Given a field in a model that uses choices:
>
> CHOICES = (
> (0, "choice_0"),
> (1, "choice_1")
> )
>
> foo = models.IntegerField(choices=CHOICES)
>
>
> If i put a value other than 0 or 1, django will accept it. Is that
> possible that we instruct Django to accept only values that are mentioned
> in CHOICES without creating a validator function.
>
> --
> 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/78d84aa0-506f-4d5c-9590-ef6325c255e0%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/CAMi_2%3DETuiuo%3D0xcz%3D3haWv5ayXpurpMazZP1rUsdEcLYxJ%3DJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django models in file sharing system

2015-12-11 Thread Vasu Dev Garg
creating a sharing manytomany field is right but how to call it in views 
and verify that user filled in the form exists?

-- 
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/7f604f3c-be19-453b-b588-9c541af8bd70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django models in file sharing system

2015-12-10 Thread Mike Dewhirst

On 11/12/2015 5:00 AM, Vasu Dev Garg wrote:

models.py :

 `class Document(models.Model):
     docfile = models.FileField(upload_to='documents/%Y/%m/%d')
     user = models.ForeignKey(User, null=False, blank= False)
`


I have created a model for file upload as shown above. docfile is the
field that represents file to be uploaded and user field stores the name
of the user that is uploading the file.I want the additional fields so
that file uploaded is visible to the ones with whom it has been shared.
Tell me the fields for achieving the sharing task.


Maybe you should use a ManyToManyField so many users may be linked to 
any Document.


https://docs.djangoproject.com/en/1.8/ref/models/fields/#manytomanyfield

eg sharing = models.ManyToManyField('User')




--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/84c40695-9652-443a-98d0-b5d416f673ea%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/566A1A35.9030701%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Django Models Joining and Normalising

2015-10-28 Thread Collin Anderson
Hello,

I'd personally keep it all in one model for as long as possible. It will 
really simplify queries and it should make your code a lot cleaner. Wait 
til you have some actual performance problems before splitting the models 
up.

Collin

On Wednesday, October 14, 2015 at 12:11:55 PM UTC-4, Yunti wrote:
>
> I'm still relatively new to Django and now working on a project that has 
> much more complex models than I've used before.  
>
> The question is about when is it best to separate out large models into 
> separate models (and the impact caused by joining the smaller models 
> together and also keeping data normalised).  
>
> I'm trying to model magazine subscriptions, which are available from 
> different suppliers - the costs vary slightly per region (due to delivery 
> costs) and the available subscriptions vary slightly dependent on payment 
> type (direct debit, card, cheque etc...). 
>
> The subscriptions have a lot of different fields for each subscriptions so 
> I'm not clear on how best to represent this in django - one large model or 
> split into smaller models.
>
> Firstly,  each supplier will have multiple magazines - to keep the data 
> normalised should the suppliers be kept in a separate table/model separate 
> to the subscriptions table? How will this impact performance when having to 
> join the data back together when querying a list of subscriptions. 
> (e.g. similarly for payment types of which there are only 4 should these 
> be pulled out into a separate table? and regions)
>
> There will be a form field for: 
> supplier
> payment type,
> region,
> should a separate model be made for these 3 fields to ease with making the 
> form and how should that tie into the above tables (if they should be 
> separated? Should I make e.g. an Input model class with ForeignKeys to each 
> of the separate tables?). 
>
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7d7cd8ae-ebd9-43f7-aa8b-ba967dc93795%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django models relation about user user_group asset asset group

2015-09-17 Thread
I think you shoud use ForeignKey.

2015-09-17 23:49 GMT+08:00 周建华 :

> I have design the base model like this:
>
> class User
> some user attr
>
> class UserGroup
> some user_group attr
>
> class Asset
>...
>
> class AssetGroup
>...
>
>
> I want to authorize asset and asset_group to user or user_group, I have no
> good idea about the models design
>
> If i set like this:
>
> class UserAsset
> user = ..
> asset = ...
>
> class UserAssetGroup
>user = ..
>asset_group = ...
>
> class UserGroupAsset
>user_group =
>asset =
>
> class UserGroupAssetGroup
> user_group =
> asset_group = ..
>
>
> If I check the user  have the asset permission or not , i will check the
> user or user group of the user isn't have the asset permission,  the user
> or user group have the asset group(the asset belong to)  permission   .
> It's will check more than 10 tables.
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9444a015-85d0-43d3-972d-cd07cda5617c%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B7P_%2Bsd50Kh-ycRY%3DqFtYBbiw4anOSrWMMqpbo2OvH23F8GHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Models PrimaryKey not incrimenting I dont understand this framework and the documentation is poorly written.

2014-07-16 Thread G Z
Thanks, I eventually solved it by using django to generate the models i 
believe it was because i was defining the db_column in the primary key and 
django said whatever, so when inspectdb built the models file it took that 
out and it started to work.

On Wednesday, July 16, 2014 12:28:27 PM UTC-6, Frank Bieniek wrote:
>
>  Hi there,
> you are telling django, you know what you are doing via
>
> managed = False -> no batteries included, please read the details here
> https://docs.djangoproject.com/en/dev/ref/models/options/
>
> There are great books out there explaining django from 
> other perspectives than the online documentation
>
> Two Scoops of Django
> http://www.amazon.com/Two-Scoops-Django-Best-Practices/dp/098146730X/
>
> Test driven development in python
>
> http://www.amazon.com/Test-Driven-Development-Python-Harry-Percival/dp/1449364829/
>
> Hope this helps
> Frank
>
>
>
> Am 16.07.14 19:08, schrieb G Z:
>  
> so I added a db trigger in oracle and it still said the same thing when 
> ever I tried to save the new addition. Also whenever I try to go to an 
> existing vm the manytomany field throws an exception that table or view 
> doesn't exist but when I goto add new it doesnt and the correct field is 
> displayed, but then when i save it says can't be null. 
>
>
> What changes from what you can see could I make to curb these problems? 
>
>
>
> class License(models.Model):
>license_id = models.AutoField(primary_key = True, editable = False, 
> db_column='license_id')
>license_authority_id = models.ForeignKey(License_authoritie,  on_delete 
> = models.PROTECT, db_column='license_authority_id')
>product = models.CharField(max_length = 20)
>
>class Meta:
>   managed = False
>db_table = 'licenses'
>   ordering = ['product']
>
>def __unicode__(self):  # Python 3: def __str__(self):
>   return self.product
>  
> class Vm_license(models.Model):
>vm_license_id = models.AutoField(primary_key = True, 
> db_column='vm_license_id')
>vm_id = models.ForeignKey(Vm,  on_delete = models.PROTECT, 
> db_column='vm_id')
>license = models.ManyToManyField( 
> License) 
>
>
>class Meta:
>   managed = False
>db_table = 'vm_licenses'
>
>
> class vm_license_admin(admin.ModelAdmin):
> #list_display = ('vm_id', 'license_id')
> list_display = ('vm_id',)
> search_fields = ('vm_id__vm_name',)
> ordering = ('vm_id',)
> filter_horizontal = ('license',)
> 
> admin.site.register(Vm_license, vm_license_admin)
>  -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/9ecf5d7f-c303-4742-9ad7-a1a56bddb716%40googlegroups.com
>  
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f43f1646-be81-457a-bb0f-38ffa918ddcc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Models PrimaryKey not incrimenting I dont understand this framework and the documentation is poorly written.

2014-07-16 Thread Frank Bieniek

Hi there,
you are telling django, you know what you are doing via

managed = False -> no batteries included, please read the details here
https://docs.djangoproject.com/en/dev/ref/models/options/

There are great books out there explaining django from
other perspectives than the online documentation

Two Scoops of Django
http://www.amazon.com/Two-Scoops-Django-Best-Practices/dp/098146730X/

Test driven development in python
http://www.amazon.com/Test-Driven-Development-Python-Harry-Percival/dp/1449364829/

Hope this helps
Frank



Am 16.07.14 19:08, schrieb G Z:
so I added a db trigger in oracle and it still said the same thing 
when ever I tried to save the new addition. Also whenever I try to go 
to an existing vm the manytomany field throws an exception that table 
or view doesn't exist but when I goto add new it doesnt and the 
correct field is displayed, but then when i save it says can't be null.



What changes from what you can see could I make to curb these problems?



class License(models.Model):
   license_id = models.AutoField(primary_key = True, editable = False, 
db_column='license_id')
   license_authority_id = models.ForeignKey(License_authoritie, 
on_delete = models.PROTECT, db_column='license_authority_id')

   product = models.CharField(max_length = 20)

   class Meta:
  managed = False
  db_table = 'licenses'
  ordering = ['product']

   def __unicode__(self):  # Python 3: def __str__(self):
  return self.product

class Vm_license(models.Model):
   vm_license_id = models.AutoField(primary_key = True, 
db_column='vm_license_id')
   vm_id = models.ForeignKey(Vm,  on_delete = models.PROTECT, 
db_column='vm_id')

   license = models.ManyToManyField(
License)


   class Meta:
  managed = False
  db_table = 'vm_licenses'


class vm_license_admin(admin.ModelAdmin):
#list_display = ('vm_id', 'license_id')
list_display = ('vm_id',)
search_fields = ('vm_id__vm_name',)
ordering = ('vm_id',)
filter_horizontal = ('license',)

admin.site.register(Vm_license, vm_license_admin)
--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com 
.
To post to this group, send email to django-users@googlegroups.com 
.

Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9ecf5d7f-c303-4742-9ad7-a1a56bddb716%40googlegroups.com 
.

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


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/53C6C42B.6050505%40produktlaunch.de.
For more options, visit https://groups.google.com/d/optout.


Re: Django Models PrimaryKey not incrimenting I dont understand this framework and the documentation is poorly written.

2014-07-16 Thread G Z
so I added a db trigger in oracle and it still said the same thing when 
ever I tried to save the new addition. Also whenever I try to go to an 
existing vm the manytomany field throws an exception that table or view 
doesn't exist but when I goto add new it doesnt and the correct field is 
displayed, but then when i save it says can't be null. 


What changes from what you can see could I make to curb these problems?



class License(models.Model):
   license_id = models.AutoField(primary_key = True, editable = False, 
db_column='license_id')
   license_authority_id = models.ForeignKey(License_authoritie,  on_delete 
= models.PROTECT, db_column='license_authority_id')
   product = models.CharField(max_length = 20)

   class Meta:
  managed = False
  db_table = 'licenses'
  ordering = ['product']

   def __unicode__(self):  # Python 3: def __str__(self):
  return self.product
 
class Vm_license(models.Model):
   vm_license_id = models.AutoField(primary_key = True, 
db_column='vm_license_id')
   vm_id = models.ForeignKey(Vm,  on_delete = models.PROTECT, 
db_column='vm_id')
   license = models.ManyToManyField(
License)


   class Meta:
  managed = False
  db_table = 'vm_licenses'


class vm_license_admin(admin.ModelAdmin):
#list_display = ('vm_id', 'license_id')
list_display = ('vm_id',)
search_fields = ('vm_id__vm_name',)
ordering = ('vm_id',)
filter_horizontal = ('license',)

admin.site.register(Vm_license, vm_license_admin)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9ecf5d7f-c303-4742-9ad7-a1a56bddb716%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Models PrimaryKey not incrimenting I dont understand this framework and the documentation is poorly written.

2014-07-15 Thread Tom Evans
On Tue, Jul 15, 2014 at 11:16 PM, G Z  wrote:
> Tom,
>
> It fails with both autofield and bigintergerfield
>
> class License(models.Model):
>license_id = models.AutoField(primary_key = True, editable = False,
> db_column='license_id')
>license_authority_id = models.ForeignKey(License_authoritie,  on_delete =
> models.PROTECT, db_column='license_authority_id')
>product = models.CharField(max_length = 20)
>
>class Meta:
>   managed = False

Two things:

Auto increment is a property set at the time you create the table, so
changing the code changes nothing unless you recreate the
table/migrations.

Secondly, you have told django you are managing that table yourself.
If you want that field auto increment, make it so.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1Jt%2BpAxLx1q%2BgyDVce%2BbA%2BvcZqiStE6SRdjApB-jw6YPw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Models PrimaryKey not incrimenting I dont understand this framework and the documentation is poorly written.

2014-07-15 Thread G Z
http://www.oracle.com/technetwork/articles/dsl/vasiliev-django-100257.html

the guide I followed from oracle.

On Tuesday, July 15, 2014 4:16:54 PM UTC-6, G Z wrote:
>
> Tom,
>
> It fails with both autofield and bigintergerfield
>
> class License(models.Model):
>license_id = models.AutoField(primary_key = True, editable = False, 
> db_column='license_id')
>license_authority_id = models.ForeignKey(License_authoritie,  on_delete = 
> models.PROTECT, db_column='license_authority_id')
>product = models.CharField(max_length = 20)
>
>class Meta:
>   managed = False
>   db_table = 'licenses'
>   ordering = ['product']
>
>def __unicode__(self):  # Python 3: def __str__(self):
>   return self.product
> class Vm_license(models.Model):
>vm_license_id = models.AutoField(primary_key = True, 
> db_column='vm_license_id')
>license_id = models.ForeignKey(License,  on_delete = models.PROTECT, 
> db_column='license_id')
>vm_id = models.ForeignKey(Vm,  on_delete = models.PROTECT, 
> db_column='vm_id')
>
>class Meta:
>   managed = False
>   db_table = 'vm_licenses'
>
>
> I get the same thing:
>
>
> Request Method: POSTRequest URL:
> http://127.0.0.1:8000/admin/portal/vm_license/add/Django Version: 
> 1.6.5Exception Type: IntegrityErrorException Value:
>
> ORA-01400: cannot insert NULL into ("DEV"."VM_LICENSES"."VM_LICENSE_ID")
>
>
>
>
>
> On Tuesday, July 15, 2014 4:09:29 PM UTC-6, Tom Evans wrote:
>
> On Tue, Jul 15, 2014 at 10:23 PM, G Z  wrote: 
> > So I have a database that we are using to collect vm statistics. It is 
> > always running and writing to a django database. 
> > I built my models file to resemble the db. However I have run into quite 
> a 
> > few issues. I was wondering if anyone else has run into these issues 
> > and found out how to solve them. 
> > 
> > First when I try to add a new entry I get an error returned that the 
> value 
> > can't be null for the primary key. 
> > 
> > ORA-01400: cannot insert NULL into ("DEV"."VM_LICENSES"."VM_LICENSE_ID") 
> > 
> > Isn't django supposed to automatically handle this when you set 
> primary_key 
> > = True? 
> > 
> > 
> > 
> > Also I want to have a list of available licenses from a table called 
> > licenses, and I want to be able to assign 
> > them by foreign key to each vm by its foreign key in an intermediary 
> table 
> > called vm_licenses. 
> > 
> > Here are the model snippets for that process. However, I can't get 
> > manytomany to work right. 
> > Bascially our system admins need to be able to manage the associated 
> > licenses for each vm. I'm trying to allow them to 
> > do this with the admin page. People keep pointing me to the 
> documentation 
> > for manytomany but obviously I can't seem to figure out 
> > how django uses already established databases. The django documentation 
> > doesn't really explain how things work. Thus, 
> > anything outside the basic blog app is unknown territory you just kinda 
> have 
> > to plug away in the dark. I'm tired of plugging away 
> > trying to figure out how this framework works. 
> > 
> > I would greatly appreciate it if someone could help me understand how 
> the 
> > django framework interacts with already established databases and how 
> > to do what I want. 
> > 
> > 
> > class License(models.Model): 
> >license_id = models.BigIntegerField(primary_key = True, editable = 
> False, 
> > db_column='license_id') 
>
> Auto increment is a feature of AutoField, not of primary keys. 
>
> https://docs.djangoproject.com/en/1.6/ref/models/fields/#autofield; 
> target="_blank" onmousedown="this.href='
> https://www.google.com/url?q\75https%3A%2F%2Fdocs.djangoproject.com%2Fen%2F1.6%2Fref%2Fmodels%2Ffie
>  
> 
>
> ...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3a9af90e-98f7-435a-8bdb-2500bf5cf792%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Models PrimaryKey not incrimenting I dont understand this framework and the documentation is poorly written.

2014-07-15 Thread G Z
Tom,

It fails with both autofield and bigintergerfield

class License(models.Model):
   license_id = models.AutoField(primary_key = True, editable = False, 
db_column='license_id')
   license_authority_id = models.ForeignKey(License_authoritie,  on_delete = 
models.PROTECT, db_column='license_authority_id')
   product = models.CharField(max_length = 20)

   class Meta:
  managed = False
  db_table = 'licenses'
  ordering = ['product']

   def __unicode__(self):  # Python 3: def __str__(self):
  return self.product
class Vm_license(models.Model):
   vm_license_id = models.AutoField(primary_key = True, 
db_column='vm_license_id')
   license_id = models.ForeignKey(License,  on_delete = models.PROTECT, 
db_column='license_id')
   vm_id = models.ForeignKey(Vm,  on_delete = models.PROTECT, db_column='vm_id')

   class Meta:
  managed = False
  db_table = 'vm_licenses'


I get the same thing:


Request Method: POSTRequest URL:
http://127.0.0.1:8000/admin/portal/vm_license/add/Django Version: 
1.6.5Exception Type: IntegrityErrorException Value:

ORA-01400: cannot insert NULL into ("DEV"."VM_LICENSES"."VM_LICENSE_ID")





On Tuesday, July 15, 2014 4:09:29 PM UTC-6, Tom Evans wrote:
>
> On Tue, Jul 15, 2014 at 10:23 PM, G Z  
> wrote: 
> > So I have a database that we are using to collect vm statistics. It is 
> > always running and writing to a django database. 
> > I built my models file to resemble the db. However I have run into quite 
> a 
> > few issues. I was wondering if anyone else has run into these issues 
> > and found out how to solve them. 
> > 
> > First when I try to add a new entry I get an error returned that the 
> value 
> > can't be null for the primary key. 
> > 
> > ORA-01400: cannot insert NULL into ("DEV"."VM_LICENSES"."VM_LICENSE_ID") 
> > 
> > Isn't django supposed to automatically handle this when you set 
> primary_key 
> > = True? 
> > 
> > 
> > 
> > Also I want to have a list of available licenses from a table called 
> > licenses, and I want to be able to assign 
> > them by foreign key to each vm by its foreign key in an intermediary 
> table 
> > called vm_licenses. 
> > 
> > Here are the model snippets for that process. However, I can't get 
> > manytomany to work right. 
> > Bascially our system admins need to be able to manage the associated 
> > licenses for each vm. I'm trying to allow them to 
> > do this with the admin page. People keep pointing me to the 
> documentation 
> > for manytomany but obviously I can't seem to figure out 
> > how django uses already established databases. The django documentation 
> > doesn't really explain how things work. Thus, 
> > anything outside the basic blog app is unknown territory you just kinda 
> have 
> > to plug away in the dark. I'm tired of plugging away 
> > trying to figure out how this framework works. 
> > 
> > I would greatly appreciate it if someone could help me understand how 
> the 
> > django framework interacts with already established databases and how 
> > to do what I want. 
> > 
> > 
> > class License(models.Model): 
> >license_id = models.BigIntegerField(primary_key = True, editable = 
> False, 
> > db_column='license_id') 
>
> Auto increment is a feature of AutoField, not of primary keys. 
>
> https://docs.djangoproject.com/en/1.6/ref/models/fields/#autofield 
>
> BigIntegerField has no auto increment properties. 
>
> Marking a field as a primary key simply means that no AutoField named 
> id is automatically added to your class, and the SQL generated for 
> that field will mark it as a primary key. 
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/65032c69-1139-480c-b739-7c54fc9a1824%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Models PrimaryKey not incrimenting I dont understand this framework and the documentation is poorly written.

2014-07-15 Thread Tom Evans
On Tue, Jul 15, 2014 at 10:23 PM, G Z  wrote:
> So I have a database that we are using to collect vm statistics. It is
> always running and writing to a django database.
> I built my models file to resemble the db. However I have run into quite a
> few issues. I was wondering if anyone else has run into these issues
> and found out how to solve them.
>
> First when I try to add a new entry I get an error returned that the value
> can't be null for the primary key.
>
> ORA-01400: cannot insert NULL into ("DEV"."VM_LICENSES"."VM_LICENSE_ID")
>
> Isn't django supposed to automatically handle this when you set primary_key
> = True?
>
>
>
> Also I want to have a list of available licenses from a table called
> licenses, and I want to be able to assign
> them by foreign key to each vm by its foreign key in an intermediary table
> called vm_licenses.
>
> Here are the model snippets for that process. However, I can't get
> manytomany to work right.
> Bascially our system admins need to be able to manage the associated
> licenses for each vm. I'm trying to allow them to
> do this with the admin page. People keep pointing me to the documentation
> for manytomany but obviously I can't seem to figure out
> how django uses already established databases. The django documentation
> doesn't really explain how things work. Thus,
> anything outside the basic blog app is unknown territory you just kinda have
> to plug away in the dark. I'm tired of plugging away
> trying to figure out how this framework works.
>
> I would greatly appreciate it if someone could help me understand how the
> django framework interacts with already established databases and how
> to do what I want.
>
>
> class License(models.Model):
>license_id = models.BigIntegerField(primary_key = True, editable = False,
> db_column='license_id')

Auto increment is a feature of AutoField, not of primary keys.

https://docs.djangoproject.com/en/1.6/ref/models/fields/#autofield

BigIntegerField has no auto increment properties.

Marking a field as a primary key simply means that no AutoField named
id is automatically added to your class, and the SQL generated for
that field will mark it as a primary key.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1KJXLhiXNAMuOz2zw7o7rd2hB4xp-dnriZVW_H31pM-2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Models PrimaryKey not incrimenting I dont understand this framework and the documentation is poorly written.

2014-07-15 Thread G Z
I can update items just not add them always the same error cannot insert 
null for the primary key





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/44097c44-dc2a-4822-8f69-0bfcf65d6e21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2014-06-04 Thread ngangsia akumbo
Thanks for this reply , am not using anybody's code. I am still studying 
django and was wondering where those fields where from. Thanks for the 
clarification. With time i will write my own field since am from Cameroon.

On Tuesday, June 3, 2014 2:16:37 AM UTC+1, Andrew Farrell wrote:
>
> Hi Mr. Akumbo,
>
> The options for Model Fields that come with django in the django.db 
> library and are listed and explained here: 
> https://docs.djangoproject.com/en/dev/ref/models/fields/#model-field-types
>
>
> Each corresponds to a different type of data. For example
>
> name = models.CharField(max_length=60)
>
> just means that the the database will store a 60-character text string 
> (VARCHAR).
>
> Other libraries can define other field types. For example, the 
> https://pypi.python.org/pypi/django-localflavor package has Model fields 
> specific to different nations such as localflavor.za.forms.ZAPostCodeField 
> for South African postal codes. If you really need to, you can look at the 
> source 
> code 
> 
>  
> of that project for an example of defining your own.
>
> It sounds like you are working through someone else's django project but 
> would find some broader context useful. If you haven't already, I would 
> recommend working through the tutorial, starting here:
> https://docs.djangoproject.com/en/dev/intro/tutorial01/
>
> best regards,
> Andrew Farrell
>
>
> On Mon, Jun 2, 2014 at 8:51 PM, ngangsia akumbo  > wrote:
>
>>
>>
>> On Sunday, June 1, 2014 7:42:13 PM UTC+1, Thomas wrote:
>>
>>>
>>> On 2014-05-31, at 4:41 AM, ngangsia akumbo  wrote:
>>>
>>> please i need some legit answer please
>>>
>>>
>>> Please give one or two specific examples of functionality you need. 
>>> There are parameters for fields which can help specialize some behaviours 
>>> without needing a new model. And there are hooks to allow specialization of 
>>> behaviours in interpretation or handling when reading or saving values 
>>> which you may find useful.
>>>
>>> afaik there is no large library of model specializations for Django, but 
>>> that may be because there is no clear large set of specializations that 
>>> would be useful.
>>>
>>> So give an example please. Is it the book name, the book author, or 
>>> something else which needs extra or restricted behaviours?
>>>
>>> - Tom
>>>
>>>
>> This is an example. Where did the get all these parameter like CharField, 
>> DateTimeField etc.
>>  
>>
>>> class Item(models.Model):
>>> name = models.CharField(max_length=60)
>>> created = models.DateTimeField(auto_now_add=True)
>>> priority = models.IntegerField(default=0)
>>> difficulty = models.IntegerField(default=0)
>>> done = models.BooleanField(default=False)
>>> class ItemAdmin(admin.ModelAdmin):
>>> list_display = ["name", "priority", "difficulty", "created", "done"]
>>> search_fields = ["name"]
>>> admin.site.register(Item, ItemAdmin)
>>>
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/44996582-811d-4731-a8d6-7133a02459b4%40googlegroups.com
>>  
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d7781eac-d29e-43f9-b524-ecbe84ff8c49%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2014-06-02 Thread Andrew Farrell
Hi Mr. Akumbo,

The options for Model Fields that come with django in the django.db library
and are listed and explained here:
https://docs.djangoproject.com/en/dev/ref/models/fields/#model-field-types


Each corresponds to a different type of data. For example


name = models.CharField(max_length=60)

just means that the the database will store a 60-character text string
(VARCHAR).

Other libraries can define other field types. For example, the
https://pypi.python.org/pypi/django-localflavor package has Model fields
specific to different nations such as localflavor.za.forms.ZAPostCodeField
for South African postal codes. If you really need to, you can look at
the source
code

of that project for an example of defining your own.

It sounds like you are working through someone else's django project but
would find some broader context useful. If you haven't already, I would
recommend working through the tutorial, starting here:
https://docs.djangoproject.com/en/dev/intro/tutorial01/

best regards,
Andrew Farrell


On Mon, Jun 2, 2014 at 8:51 PM, ngangsia akumbo  wrote:

>
>
> On Sunday, June 1, 2014 7:42:13 PM UTC+1, Thomas wrote:
>
>>
>> On 2014-05-31, at 4:41 AM, ngangsia akumbo  wrote:
>>
>> please i need some legit answer please
>>
>>
>> Please give one or two specific examples of functionality you need. There
>> are parameters for fields which can help specialize some behaviours without
>> needing a new model. And there are hooks to allow specialization of
>> behaviours in interpretation or handling when reading or saving values
>> which you may find useful.
>>
>> afaik there is no large library of model specializations for Django, but
>> that may be because there is no clear large set of specializations that
>> would be useful.
>>
>> So give an example please. Is it the book name, the book author, or
>> something else which needs extra or restricted behaviours?
>>
>> - Tom
>>
>>
> This is an example. Where did the get all these parameter like CharField,
> DateTimeField etc.
>
>
>> class Item(models.Model):
>> name = models.CharField(max_length=60)
>> created = models.DateTimeField(auto_now_add=True)
>> priority = models.IntegerField(default=0)
>> difficulty = models.IntegerField(default=0)
>> done = models.BooleanField(default=False)
>> class ItemAdmin(admin.ModelAdmin):
>> list_display = ["name", "priority", "difficulty", "created", "done"]
>> search_fields = ["name"]
>> admin.site.register(Item, ItemAdmin)
>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/44996582-811d-4731-a8d6-7133a02459b4%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2By5TLYDLe%2By_yehWr8RG2SGt0V6GLf3GWQyYxAVfJ36fWe8jg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2014-06-02 Thread ngangsia akumbo


On Sunday, June 1, 2014 7:42:13 PM UTC+1, Thomas wrote:
>
>
> On 2014-05-31, at 4:41 AM, ngangsia akumbo  > wrote:
>
> please i need some legit answer please
>
>
> Please give one or two specific examples of functionality you need. There 
> are parameters for fields which can help specialize some behaviours without 
> needing a new model. And there are hooks to allow specialization of 
> behaviours in interpretation or handling when reading or saving values 
> which you may find useful.
>
> afaik there is no large library of model specializations for Django, but 
> that may be because there is no clear large set of specializations that 
> would be useful.
>
> So give an example please. Is it the book name, the book author, or 
> something else which needs extra or restricted behaviours?
>
> - Tom
>
>
This is an example. Where did the get all these parameter like CharField, 
DateTimeField etc.
 

> class Item(models.Model):
> name = models.CharField(max_length=60)
> created = models.DateTimeField(auto_now_add=True)
> priority = models.IntegerField(default=0)
> difficulty = models.IntegerField(default=0)
> done = models.BooleanField(default=False)
> class ItemAdmin(admin.ModelAdmin):
> list_display = ["name", "priority", "difficulty", "created", "done"]
> search_fields = ["name"]
> admin.site.register(Item, ItemAdmin)
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/44996582-811d-4731-a8d6-7133a02459b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django models

2014-06-01 Thread Tom Lockhart

On 2014-05-31, at 4:41 AM, ngangsia akumbo  wrote:

> please i need some legit answer please

Please give one or two specific examples of functionality you need. There are 
parameters for fields which can help specialize some behaviours without needing 
a new model. And there are hooks to allow specialization of behaviours in 
interpretation or handling when reading or saving values which you may find 
useful.

afaik there is no large library of model specializations for Django, but that 
may be because there is no clear large set of specializations that would be 
useful.

So give an example please. Is it the book name, the book author, or something 
else which needs extra or restricted behaviours?

- Tom


> 
> we have in the models forexaple
> 
> class Book():
> 
> name = InputTextField
> Autho = 
> 
> 
> Please are there not more parmaters that can hel you to better define your 
> model. Are there no library for models?
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/cb57997d-ac3e-40a4-b7f8-791db176%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Please consider the environment before printing this message.
This message may be privileged and/or confidential, and the sender does not 
waive any related rights and obligations.  Any distribution, use or copying of 
this message or the information it contains by other than an intended recipient 
is unauthorized.  If you received this message in error, please immediately 
advise me by return e-mail or phone.  All information, references, images, 
programs, source code, or other materials whatsoever contained in, or supplied 
with, this document are TRADE SECRETS and governed by the Uniform Trade Secrets 
Act.  User assumes all direct and consequential liabilities and costs that 
result from any unauthorized disclosure or use of this information.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/D64B5C18-5A49-4303-8BCC-2740FBA3B3BA%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Models: How to allow users to select an image from a choice of 3 pictures

2012-07-24 Thread Melvyn Sopacua
On 16-7-2012 3:26, croberts wrote:
> I am familiar with the use of Field.choices for text.

Then that's all you need. Let the template handle the image rendered:
EMO_CHOICES = (
('smiley_sad.png', 'sad sad emo'),
('smiley_neutral.png', 'ask me later'),
('smiley_happy.png', 'happy happy joy joy'),
)

in template:
{% load static %}
...


And of course you can dress it up as Ivan showed, but the basic
principles are the same.

-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Models: How to allow users to select an image from a choice of 3 pictures

2012-07-15 Thread Ivan Ivanov
На Sun, 15 Jul 2012 18:26:02 -0700 (PDT)
croberts  написа:

> I am familiar with the use of Field.choices for text.
> 
> However, I'd like the same option for images.  Is this possible?  I
> want users to select one image from a list of 3 and be able to save
> this.  They can later come back in and change it if they wish.  I
> know that in order to save this, it must be in Models.
> 
> The idea:
> 
> Each day, the has the option of selecting an image: happy face, sad
> face, smiley face of how they are feeling.  Their selection is
> saved.  They can go in later to change it if they wish.
> 
> ImageField doesn't seem to do this.  It seems to only allow for
> uploaded images as opposed to a choice.
> 
Use Choice field with image in the option. You do not need FIleField,
couse you don't operate with files at all. You just want to put an
image in a select.

There are several ways to achieve this:
background image (pure html+css)
http://binnyva.blogspot.com/2006/01/icons-for-select-menu-options-in.html

Jquery UI;
or something like this:
http://www.marghoobsuleman.com/jquery-image-dropdown

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django Models Foreign Key Issue!

2012-05-29 Thread Eugène Ngontang
Hi all!

The issue was not from Django side, but really from my models
implementation.

I made mistake when propagating my associative tables through other tables.
And there was another unity constraint blocking the one i wanted to set.

I don't think it's necessary to explain you all here, because it's purely
model issue, not django models issue.

But I fixed the problem.

Thanks anyway for eading.

2012/5/28 Eugene NGONTANG 

> I encountered a problem using Django foreign key unique_together for
> one of my models.
>
> I have three models (representing three tables in the database), host,
> user, and job.
>
> - user has a host foreign key
> - job has a user foreign key and a host foreign key : Because we can
> have the same user on two different host, and the same job for the
> users. But we can't (should not) have the same job name duplicate for
> the same user and host id.
>
> I use this in my class model :
>
> class Meta:
> unique_together = ("job_name", "user", "host")
>
> It works for "./manage.py sqall my_app", and "./manage.py syncdb"
>
> Things go fine untill i try to create a job with the same name in  the
> admin interface for two different users on the same host.
>
> The django admin accept the request, but it blocks at the sql level,
> and returns this execption in the error page:
>
>  Exception Value: (1062, "Duplicate entry 'my_command-5' for key
> 'job_name'")
>
> I can't use this :
> class Meta:
> unique_together = (("job_name", "user"), ("user",
> "host")).
>
> It will be take as to two unique_together case.
>
> That's what the "./manage.py sqall my_app" has generated in the
> standard output:
> ..
>   UNIQUE (`job_name`, `user_id`, `host_id`)
> .
>
> But how to tell django to tell the sgbd that unicité is to be applied
> on the job_name, the user_id and the host_id?
>
>
> Has anyone encontered this issue?
>
> Thanks for looking.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
ngont...@epitech.net
sympav...@gmail.com

*Aux hommes il faut un chef, et au** chef il faut des hommes!
L'habit ne fait pas le moine, mais lorsqu'on te voit on te juge!
*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models and different types

2012-05-11 Thread Michael da Silva Pereira
Hi,

Using a form did the trick, I did however have a issue with datetime
formats. It appears the formats I got from the string values are not
recognized.

This sorted me out with that:
   from dateutil import parser

if str(Customer._meta.get_field("pastel_"+col).get_internal_type())
== "DateTimeField":
try:
row_form_ready["pastel_"+col] = parser.parse(row[col])
except:
row_form_ready["pastel_"+col] = "-00-00 00:00:00"


-- Mike



On 11 May 2012 13:54, Tom Evans  wrote:

> On Fri, May 11, 2012 at 12:39 PM, Michael da Silva Pereira
>  wrote:
> >
> > Hi,
> >
> > Looking for some ideas around a type / conversion matching
> > issue I'm having with a big django model.
> > The model has tons of variables, and all being of different types
> > (int, nullbool, date, datetime, string).
> >
> > I'm trying to pass data from a different database into the django
> > model, but the other DB passes the info to me as string.
> >
> > I don't really want to do type conversions for each and every field,
> > there are around 180 odd. Is there not some sort of function that be
> > used to automatically for the conversion?
> >
> > Any ideas?
> >
> > -- Mike
> >
>
> Could you access the 'other' database via a django model (an unmanaged
> model probably)?
>
> Models themselves will happily accept string data, eg a DateField
> would happily accept the string "2012-01-12.
>
> Alternately, could you transform the values extracted from the other
> database into a query string? If so, you could use a form to process
> the data, as turning arbitrary string fields into model fields is what
> model forms are designed to do.
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 

*
*
*Tradepage, now part of the Cloud Group, is an Authorised Google Apps for 
Business Reseller.  For only R450 per user per year, get Business Email, 
Calendars, Documents, syncing with mobile devices and much more. Find out 
more: http://www.tradepage.co.za/google-apps-for-business*


This email and all contents are subject to the following disclaimer:
http://www.tradepage.co.za/disclaimer

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models and different types

2012-05-11 Thread Tom Evans
On Fri, May 11, 2012 at 12:39 PM, Michael da Silva Pereira
 wrote:
>
> Hi,
>
> Looking for some ideas around a type / conversion matching
> issue I'm having with a big django model.
> The model has tons of variables, and all being of different types
> (int, nullbool, date, datetime, string).
>
> I'm trying to pass data from a different database into the django
> model, but the other DB passes the info to me as string.
>
> I don't really want to do type conversions for each and every field,
> there are around 180 odd. Is there not some sort of function that be
> used to automatically for the conversion?
>
> Any ideas?
>
> -- Mike
>

Could you access the 'other' database via a django model (an unmanaged
model probably)?

Models themselves will happily accept string data, eg a DateField
would happily accept the string "2012-01-12.

Alternately, could you transform the values extracted from the other
database into a query string? If so, you could use a form to process
the data, as turning arbitrary string fields into model fields is what
model forms are designed to do.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models

2012-01-30 Thread Stanwin Siow
ok got it. I read the document and it was good stuff.

Just got confused with copying pasting into my models.py. Thanks alot once 
again.

:)

Best Regards,

Stanwin Siow



On Jan 30, 2012, at 10:02 PM, Michael Elkins wrote:

> On Mon, Jan 30, 2012 at 09:53:18PM +0800, Stanwin Siow wrote:
>> but once my terminal creates the model classes do i have to copy it into my 
>> app's model.py?
> 
> yes, you will need to copy the output to your models.py.  you may need to 
> edit it to put the models in order so that dependencies like foreign keys in 
> the model definitions are satisified.  see the link i posted earlier about 
> inspectdb for details on what you may need to edit.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models

2012-01-30 Thread Michael Elkins

On Mon, Jan 30, 2012 at 09:53:18PM +0800, Stanwin Siow wrote:

but once my terminal creates the model classes do i have to copy it into my 
app's model.py?


yes, you will need to copy the output to your models.py.  you may 
need to edit it to put the models in order so that dependencies 
like foreign keys in the model definitions are satisified.  see 
the link i posted earlier about inspectdb for details on what you 
may need to edit.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models

2012-01-30 Thread Stanwin Siow
sorry to bother you again michael

but once my terminal creates the model classes do i have to copy it into my 
app's model.py?

I wanted to be sure.


Best Regards,

Stanwin Siow



On Jan 30, 2012, at 9:35 PM, Michael Elkins wrote:

> On Mon, Jan 30, 2012 at 09:26:10PM +0800, Stanwin Siow wrote:
>> However what does this error say?
>> 
>> ImportError: Settings cannot be imported, because environment variable 
>> DJANGO_SETTINGS_MODULE is undefined.
> 
> If you have a manage.py for your project, you can just run "manage.py 
> inspectdb" and it will use the DATABASES defined in your settings.py.
> 
> manage.py is just a wrapper around django-admin.py that sets the 
> DJANGO_SETTINGS_MODULE and PYTHONPATH for you.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models

2012-01-30 Thread Stanwin Siow
Thank you so much.

This information is very useful. It work like a charm for me.

Thank you once again mike. Cheers

Best Regards,

Stanwin Siow



On Jan 30, 2012, at 9:35 PM, Michael Elkins wrote:

> On Mon, Jan 30, 2012 at 09:26:10PM +0800, Stanwin Siow wrote:
>> However what does this error say?
>> 
>> ImportError: Settings cannot be imported, because environment variable 
>> DJANGO_SETTINGS_MODULE is undefined.
> 
> If you have a manage.py for your project, you can just run "manage.py 
> inspectdb" and it will use the DATABASES defined in your settings.py.
> 
> manage.py is just a wrapper around django-admin.py that sets the 
> DJANGO_SETTINGS_MODULE and PYTHONPATH for you.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models

2012-01-30 Thread Michael Elkins

On Mon, Jan 30, 2012 at 09:26:10PM +0800, Stanwin Siow wrote:

However what does this error say?

ImportError: Settings cannot be imported, because environment variable 
DJANGO_SETTINGS_MODULE is undefined.


If you have a manage.py for your project, you can just run 
"manage.py inspectdb" and it will use the DATABASES defined in 
your settings.py.


manage.py is just a wrapper around django-admin.py that sets the 
DJANGO_SETTINGS_MODULE and PYTHONPATH for you.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models

2012-01-30 Thread Stanwin Siow
hi michael,

Thanks for the tip. It is a huge step in my progress.

However what does this error say?

ImportError: Settings cannot be imported, because environment variable 
DJANGO_SETTINGS_MODULE is undefined.

Best Regards,

Stanwin Siow



On Jan 30, 2012, at 8:37 PM, Michael Elkins wrote:

> On Mon, Jan 30, 2012 at 04:13:50AM -0800, St@n wrote:
>> How do i ask django to query for a table that is already created in
>> the database but not part of the models.py?
>> 
>> the models.py is used to described the database and to create tables
>> with that models.py. However i already have my tables created prior to
>> creating the django app.
>> 
>> How then do i get django to query those tables created before?
> 
> You can use "django-admin.py inspectdb" to generate a models.py based on an 
> existing database:
> 
> https://docs.djangoproject.com/en/1.3/ref/django-admin/#inspectdb
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models

2012-01-30 Thread Michael Elkins

On Mon, Jan 30, 2012 at 04:13:50AM -0800, St@n wrote:

How do i ask django to query for a table that is already created in
the database but not part of the models.py?

the models.py is used to described the database and to create tables
with that models.py. However i already have my tables created prior to
creating the django app.

How then do i get django to query those tables created before?


You can use "django-admin.py inspectdb" to generate a models.py 
based on an existing database:


https://docs.djangoproject.com/en/1.3/ref/django-admin/#inspectdb

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models design question

2011-10-17 Thread omerd
Thank you very much!
I choose the first option for now.
If I have any problems, I will write them here

On Oct 17, 2:51 pm, Stuart  wrote:
> Hello Omer --
>
> I believe you have two options. You could use the AttributeValue
> approach I described earlier. You could add features to take care of
> 'data types' and the like. The work may be quite tedious, but it has
> the advantage of not being clever. In other words, you would do the
> work to implement each feature as you like, with no magic involved.
>
> The other approach is to extend django/python itself. Basically the
> approach here is what has been called dynamic models. You can google
> for it, but your best bet is probably this blog post and the pages it
> references.http://martyalchin.com/2007/aug/14/dynamic-models-in-real-world/
> However, note that the article is over four years old. You would no
> doubt have to update this approach for django 1.3. This approach would
> require knowledge of django/python extension points and likely some
> internals. It's probably the "better" approach assuming you are up for
> it. You would have to decide when to construct these dynamic models,
> among many other decisions.
>
> I'm on holiday for the next couple days, but I will check back with
> the list to see how you're getting on when I return.
>
> Good luck!
>
> --Stuart

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models design question

2011-10-17 Thread Stuart
Hello Omer --

I believe you have two options. You could use the AttributeValue
approach I described earlier. You could add features to take care of
'data types' and the like. The work may be quite tedious, but it has
the advantage of not being clever. In other words, you would do the
work to implement each feature as you like, with no magic involved.

The other approach is to extend django/python itself. Basically the
approach here is what has been called dynamic models. You can google
for it, but your best bet is probably this blog post and the pages it
references. http://martyalchin.com/2007/aug/14/dynamic-models-in-real-world/
However, note that the article is over four years old. You would no
doubt have to update this approach for django 1.3. This approach would
require knowledge of django/python extension points and likely some
internals. It's probably the "better" approach assuming you are up for
it. You would have to decide when to construct these dynamic models,
among many other decisions.

I'm on holiday for the next couple days, but I will check back with
the list to see how you're getting on when I return.


Good luck!

--Stuart

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models design question

2011-10-16 Thread omerd
I should also mention that one AttributeValue table for all the
registrations isn't good for my purpose, because it says that the
Value column must have a specific type field. I want that every detail
(Atrribute) will have the option to be from any field type
(CharField,DateTimeField, etc).

On Oct 15, 9:37 pm, omerd  wrote:
> Thank you for the response.
>
> As stuart wrote, i should give more details about the website.
> Currently let's suppose I have 2 interesting tables (I'm not sure that
> the relationship between these 2 tables is well designed):
>
> 1. Details, that contains all the possible information that should be
> provided to register for something.
> For example: first name, last name, phone number, address etc.
>
> I should mention again that every registration needs other set of
> details
>
> 2. Registration, that have the following columns:
> admin (the admin of the registration), registration_name,id , foreign
> key to Details(many to many).
>
> actually, I chose the first model that sturat described. I wan't that
> some users that have the appropriate privileges (super-user) will be
> able to define new registration for something. For example, let's
> suppose that a new user asks me to use the infrastructure of the
> website to create a new registration for his handgun shop because he
> wants to know the amount of arms that have to be taken from the
> factory.
> So, I, as the site admin, adding 2 new record to the Details table
> (caliber and shell capacity), and a new record to the registration
> table. This is very simple and can be done from the admin site.
>
> The problem is that I need to change the code (models.py) and add a
> new model called "Handgun"- a model for the registration that has
> those columns:
> Foreign key to Registration table, Shell capacity, Caliber Capacity.
>
> I don't want to change the code (models.py) whenever I'm adding a new
> registration record. this attitude is bad and not scalable.
>
> I'm need your advice!
>
> On Oct 14, 6:30 pm, Stuart  wrote:
>
>
>
>
>
>
>
> > Hello omerd --
>
> > If you give some concrete examples of what you are trying to do,
> > including providing your current models.py code, it will make it
> > easier for us to help you.
>
> > Since you have Registration and Details models, I am assuming you want
> > the user to be able to create/define these items, rather than
> > specifying them yourself beforehand. So if I am a user of your system,
> > I can define a new Registration for handguns, and indicate that I want
> > Details of caliber and shell capacity. Then another user can access
> > the system and register his .38 six-shooter. Is that the kind of thing
> > you have in mind? If so, you are essentially giving the users the
> > ability to define a new table (Registration) with certain columns
> > (Details), and then letting them populate it (and you would store the
> > actual values using another model like 'AttributeValue').
>
> > On the other hand, if you are defining the subjects beforehand as the
> > developer, you will want a different approach altogether. In that case
> > you might consider something like model inheritance (https://
> > docs.djangoproject.com/en/1.3/topics/db/models/#model-inheritance) or
> > some other technique to keep things DRY as you add dozens of
> > registration subjects.
>
> > Hope that helps,
>
> > --Stuart
>
> > On Oct 14, 6:53 am, omerd  wrote:
>
> > > Hello everybody,
> > > I am writing my first web application with Django.
>
> > > I want to create a web of registration for many subjects.
> > > However, each subject require different set of details to be supplied
> > > so I don't know which models should I have in the database.
>
> > > Currently I have two models:
> > > Registration - describes a registration (each record is a different
> > > subject)
> > > Details - describes all the possible details which may be necessary to
> > > register.
>
> > > Now, each Registration instance should contain a list of the necessary
> > > details, so i guess that Registration and Details are Many-To-Many
> > > connected.
>
> > > My question is - how the other model(s) which contains the actual
> > > details and a FK to Registration model should look like? I don't want
> > > to create a new model for each Registration record and place the
> > > necessary details hardcoded in the model fields. What if I have 30
> > > records in Registration table ?!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models design question

2011-10-15 Thread omerd
Thank you for the response.

As stuart wrote, i should give more details about the website.
Currently let's suppose I have 2 interesting tables (I'm not sure that
the relationship between these 2 tables is well designed):

1. Details, that contains all the possible information that should be
provided to register for something.
For example: first name, last name, phone number, address etc.

I should mention again that every registration needs other set of
details

2. Registration, that have the following columns:
admin (the admin of the registration), registration_name,id , foreign
key to Details(many to many).

actually, I chose the first model that sturat described. I wan't that
some users that have the appropriate privileges (super-user) will be
able to define new registration for something. For example, let's
suppose that a new user asks me to use the infrastructure of the
website to create a new registration for his handgun shop because he
wants to know the amount of arms that have to be taken from the
factory.
So, I, as the site admin, adding 2 new record to the Details table
(caliber and shell capacity), and a new record to the registration
table. This is very simple and can be done from the admin site.

The problem is that I need to change the code (models.py) and add a
new model called "Handgun"- a model for the registration that has
those columns:
Foreign key to Registration table, Shell capacity, Caliber Capacity.

I don't want to change the code (models.py) whenever I'm adding a new
registration record. this attitude is bad and not scalable.

I'm need your advice!


On Oct 14, 6:30 pm, Stuart  wrote:
> Hello omerd --
>
> If you give some concrete examples of what you are trying to do,
> including providing your current models.py code, it will make it
> easier for us to help you.
>
> Since you have Registration and Details models, I am assuming you want
> the user to be able to create/define these items, rather than
> specifying them yourself beforehand. So if I am a user of your system,
> I can define a new Registration for handguns, and indicate that I want
> Details of caliber and shell capacity. Then another user can access
> the system and register his .38 six-shooter. Is that the kind of thing
> you have in mind? If so, you are essentially giving the users the
> ability to define a new table (Registration) with certain columns
> (Details), and then letting them populate it (and you would store the
> actual values using another model like 'AttributeValue').
>
> On the other hand, if you are defining the subjects beforehand as the
> developer, you will want a different approach altogether. In that case
> you might consider something like model inheritance (https://
> docs.djangoproject.com/en/1.3/topics/db/models/#model-inheritance) or
> some other technique to keep things DRY as you add dozens of
> registration subjects.
>
> Hope that helps,
>
> --Stuart
>
> On Oct 14, 6:53 am, omerd  wrote:
>
>
>
>
>
>
>
> > Hello everybody,
> > I am writing my first web application with Django.
>
> > I want to create a web of registration for many subjects.
> > However, each subject require different set of details to be supplied
> > so I don't know which models should I have in the database.
>
> > Currently I have two models:
> > Registration - describes a registration (each record is a different
> > subject)
> > Details - describes all the possible details which may be necessary to
> > register.
>
> > Now, each Registration instance should contain a list of the necessary
> > details, so i guess that Registration and Details are Many-To-Many
> > connected.
>
> > My question is - how the other model(s) which contains the actual
> > details and a FK to Registration model should look like? I don't want
> > to create a new model for each Registration record and place the
> > necessary details hardcoded in the model fields. What if I have 30
> > records in Registration table ?!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models design question

2011-10-14 Thread Stuart
Hello omerd --

If you give some concrete examples of what you are trying to do,
including providing your current models.py code, it will make it
easier for us to help you.

Since you have Registration and Details models, I am assuming you want
the user to be able to create/define these items, rather than
specifying them yourself beforehand. So if I am a user of your system,
I can define a new Registration for handguns, and indicate that I want
Details of caliber and shell capacity. Then another user can access
the system and register his .38 six-shooter. Is that the kind of thing
you have in mind? If so, you are essentially giving the users the
ability to define a new table (Registration) with certain columns
(Details), and then letting them populate it (and you would store the
actual values using another model like 'AttributeValue').

On the other hand, if you are defining the subjects beforehand as the
developer, you will want a different approach altogether. In that case
you might consider something like model inheritance (https://
docs.djangoproject.com/en/1.3/topics/db/models/#model-inheritance) or
some other technique to keep things DRY as you add dozens of
registration subjects.


Hope that helps,

--Stuart

On Oct 14, 6:53 am, omerd  wrote:
> Hello everybody,
> I am writing my first web application with Django.
>
> I want to create a web of registration for many subjects.
> However, each subject require different set of details to be supplied
> so I don't know which models should I have in the database.
>
> Currently I have two models:
> Registration - describes a registration (each record is a different
> subject)
> Details - describes all the possible details which may be necessary to
> register.
>
> Now, each Registration instance should contain a list of the necessary
> details, so i guess that Registration and Details are Many-To-Many
> connected.
>
> My question is - how the other model(s) which contains the actual
> details and a FK to Registration model should look like? I don't want
> to create a new model for each Registration record and place the
> necessary details hardcoded in the model fields. What if I have 30
> records in Registration table ?!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models and inheritance

2011-03-12 Thread Mark J. Nenadov
> When you define an abstract model, you have to define the ``abstract''
> property inside its 
> Meta.http://docs.djangoproject.com/en/1.2/ref/models/options/#abstracthttp://docs.djangoproject.com/en/1.2/topics/db/models/#abstract-base-...
>
> That way your abstract class can inherit models.Model and will have no
> database table created.
>
> Michal Petrucha
>
>  signature.asc
> < 1KViewDownload

Thank you Michal for your kind and useful help!

~Mark

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django models and inheritance

2011-03-11 Thread Michal Petrucha
> If I have my abstract super classes inherit models.Model,  things
> technically can work. However, I arrive with a rather overly complex
> SQL design generated from them (like needless tables for abstract
> super classes).
> 
> On the other hand, if I have my abstract super classes NOT inherit
> models.Model and then use multiple inheritance on my subclasses (ie.
> have the subclasses inherit both models.Model and their Super class),
> then I end up with non-functional SQL tables (ie. the SQL table for a
> model would not contain critical fields that in the model had been
> inherited from their super class).
> 
> Am I missing something? Is there a way to have my models include
> properties inherited from an abstract super class into the SQL it
> generates? And ideally without creating tables for each abstract super
> class? Or is this just too much in the way of complex OO for
> models.py, and maybe I'm just over-doing it and  an experienced Django
> developer will point out the futility of what I'm trying.

When you define an abstract model, you have to define the ``abstract''
property inside its Meta.
http://docs.djangoproject.com/en/1.2/ref/models/options/#abstract
http://docs.djangoproject.com/en/1.2/topics/db/models/#abstract-base-classes

That way your abstract class can inherit models.Model and will have no
database table created.

Michal Petrucha


signature.asc
Description: Digital signature


Re: django models: two foreignky for "User"

2010-11-09 Thread Marcos Moyano

Use related_name
(http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.related_name)

Rgds,
Marcos

At Tue, 9 Nov 2010 07:20:45 -0800 (PST),
luckrill wrote:
> 
> I write following models:
> 
> class article(models.Model):
> created_by = models.ForeignKey('User')
> edited_by = models.ForeignKey('User')
> 
> django report error. How to ForeignKey "User" for two field.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django models/ sqlalchemy

2009-08-26 Thread drakkan

You can:

1) redefine your sa models in django models.py
2) use sqlalchemy-migrate for database migration and initial data
population, I never used json for initial data with migrate

drakkan

On 26 Ago, 17:29, ajay  wrote:
> HI,
>     I have used sqlalchemy for database model creation instead django
> default ORM.
>     Now i need to use fixture to load the initial data as i run test
> cases.
>     This is error message "DeserializationError: Invalid model
> identifier:"
>     The models are not defined in models.py file as i am using
> alchemy .
>     Is there any way i can use fixture to load initial data in my
> database .
>
>     my structure of app look like this
>          models.py
>          views.py
>           alchemy.py     - database models are defined here .
>           tests.py
>
>    I am using json as serialized data.
>
> With Thanks
> Vijay
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Models blank=False Problem

2009-02-19 Thread Karen Tracey
On Thu, Feb 19, 2009 at 7:45 AM, madhav  wrote:

>
> I have a model something like this:
> class CandidateEmailMessage(models.Model):
>from_email = models.EmailField(max_length=100)
>to_email = models.EmailField(max_length=100)
>body = models.TextField()
>objects = CandidateEmailMessageManager()
>
> As the django documentation says blank=False,null=False are there by
> default. So if I do
> candidate_email_object = CandidateEmailMessage
> (from_email='',to_email='',body='');
> candidate_email_object.save()
> it should not be saved. But its actually saving, an empty object. I am
> running the above script in my test case. How is it actually allowing
> that?
>

Currently validation is only being done at the form level.  If you created a
ModelForm for this model and tried to specify blanks for those fields the
form's is_valid() method would return False and the error messages would
indicate that values were required for those fields.  But you've not used a
form, and we don't yet have model validation, so right now you don't get an
error.

You might find this post by Malcolm useful if you want to do some validation
like this in the absence of built-in model validation in Django:

http://www.pointy-stick.com/blog/2008/10/15/django-tip-poor-mans-model-validation/

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Models + ManyToMany

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 7:08 PM, rabbi  wrote:

>
> Thanks Karen,
> I actually deleted the thread soon after posting it as I came across
> what you have written above.
> Somehow you still managed to reply to a deleted thread though...?
> Impressive
>

I don't use the Google groups  interface to read the group, I read it as
mail.  Deleting the message from the group doesn't remove it from the
mailboxes of anyone who gets email copies of messages.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Models + ManyToMany

2009-01-08 Thread rabbi

Thanks Karen,
I actually deleted the thread soon after posting it as I came across
what you have written above.
Somehow you still managed to reply to a deleted thread though...?
Impressive

On Jan 9, 1:04 am, "Karen Tracey"  wrote:
> On Thu, Jan 8, 2009 at 12:06 PM, rabbi  wrote:
>
> > Hi,
> > I have a question that is probably very simple to answer.
>
> > class Example(models.Model):
> >    value = models.CharField(max_length=200)
> >    related_examples = models.ManyToMany
> > ('self',related_name='related_example_set')
>
> > If I define a ManyToMany relationship like the one above and I want to
> > access all Example's that are related to a specific Example instance,
> > which of the following methods should I use?
>
> >   1) related_examples.all()
> >   2) related_examples.all().append(related_example_set.all())
>
> > The reason I ask is that it is possible that one instance is assigned
> > a relationship to another instance, but the relationship is not
> > defined in the other direction.
>
> > E.g. x.add(y) BUT NOT y.add(x)
>
> ManyToMany fields to 'self' are symmetrical by default:
>
> http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.mod...
>
> Since you have not specified symmetrical=False I do not think your 2nd
> option will even work, since per the docs the example_set attribute will not
> be created for a symmetrical ManyToMany relationship to 'self'.
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Models + ManyToMany

2009-01-08 Thread Karen Tracey
On Thu, Jan 8, 2009 at 12:06 PM, rabbi  wrote:

>
> Hi,
> I have a question that is probably very simple to answer.
>
> class Example(models.Model):
>value = models.CharField(max_length=200)
>related_examples = models.ManyToMany
> ('self',related_name='related_example_set')
>
> If I define a ManyToMany relationship like the one above and I want to
> access all Example's that are related to a specific Example instance,
> which of the following methods should I use?
>
>   1) related_examples.all()
>   2) related_examples.all().append(related_example_set.all())
>
> The reason I ask is that it is possible that one instance is assigned
> a relationship to another instance, but the relationship is not
> defined in the other direction.
>
> E.g. x.add(y) BUT NOT y.add(x)
>
>
ManyToMany fields to 'self' are symmetrical by default:

http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ManyToManyFields.symmetrical

Since you have not specified symmetrical=False I do not think your 2nd
option will even work, since per the docs the example_set attribute will not
be created for a symmetrical ManyToMany relationship to 'self'.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models

2008-12-22 Thread kev

Alright thanks a lot.

On Dec 22, 3:06 pm, bruno desthuilliers
 wrote:
> On 22 déc, 17:10, kev  wrote:
>
>
>
> > Hello,
> > Im reading a django book and it adds friends to user authentication
> > system by making:
>
> > (was .96)
>
> > class Friendship(models.Model):
> >   from_friend = models.ForeignKey(
> >     User, related_name='friend_set'
> >   )
> >   to_friend = models.ForeignKey(
> >     User, related_name='to_friend_set'
> >   )
> >   def __str__(self):
> >     return '%s, %s' % (
> >       self.from_friend.username,
> >       self.to_friend.username
> >     )
> >   class Admin:
> >     pass
> >   class Meta:
> >     unique_together = (('to_friend', 'from_friend'), )
>
> > But for this to work, you have to add friendship both ways.
>
> Nope. You have to *query* it both ways.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models

2008-12-22 Thread bruno desthuilliers



On 22 déc, 17:10, kev  wrote:
> Hello,
> Im reading a django book and it adds friends to user authentication
> system by making:
>
> (was .96)
>
> class Friendship(models.Model):
>   from_friend = models.ForeignKey(
> User, related_name='friend_set'
>   )
>   to_friend = models.ForeignKey(
> User, related_name='to_friend_set'
>   )
>   def __str__(self):
> return '%s, %s' % (
>   self.from_friend.username,
>   self.to_friend.username
> )
>   class Admin:
> pass
>   class Meta:
> unique_together = (('to_friend', 'from_friend'), )
>
> But for this to work, you have to add friendship both ways.

Nope. You have to *query* it both ways.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models

2008-12-22 Thread kev

I see what you are saying but there are few drawbacks:
1) 2 queries instead of one.
2) When you combine into friends_all or something, you need to keep
track of which was friend vs which is user.

I was thinking more on the lines of this:
Each User has a UserProfile which i defined. In UserProfile define a
onetomany relationship which points to a specific entry in friends
relationship so that both friends would point to the same friendship
entry.

Im not a django or database relationships expert so im not sure if
this would even work or whether it would have better performance than
2 queries (usually you select entries more than insert them).

Any feedback is welcome

Kevin

On Dec 22, 12:28 pm, Jason Sidabras  wrote:
> The way I was thinking of doing it was to have two foreignkeys named
> friend1 and friend2 then when you do your list you could run
> (something like)
>
> friends = Friendship.objects.get(friend1__exact=user)
> and
> friends2 = Friendship.objects.get(friend2__exact=user)
>
> Then you have a complete instance of the friends. I'm not by a django
> computer right now
> to figure it out but friends and friends2 could be added together to
> pass one variable.
>
> On Dec 22, 10:10 am, kev  wrote:
>
> > Hello,
> > Im reading a django book and it adds friends to user authentication
> > system by making:
>
> > (was .96)
>
> > class Friendship(models.Model):
> >   from_friend = models.ForeignKey(
> >     User, related_name='friend_set'
> >   )
> >   to_friend = models.ForeignKey(
> >     User, related_name='to_friend_set'
> >   )
> >   def __str__(self):
> >     return '%s, %s' % (
> >       self.from_friend.username,
> >       self.to_friend.username
> >     )
> >   class Admin:
> >     pass
> >   class Meta:
> >     unique_together = (('to_friend', 'from_friend'), )
>
> > But for this to work, you have to add friendship both ways. Ex/ user1 -> 
> > user2 and user2 -> user1 which means almost duplicate entries in
>
> > this model. And anytime you modify one friendship, you have to do the
> > same to the other one.
>
> > Is there a better way to do this so that only one entry exists in the
> > db? Any suggestions are welcome!
>
> > Kevin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models

2008-12-22 Thread Jason Sidabras

The way I was thinking of doing it was to have two foreignkeys named
friend1 and friend2 then when you do your list you could run
(something like)

friends = Friendship.objects.get(friend1__exact=user)
and
friends2 = Friendship.objects.get(friend2__exact=user)

Then you have a complete instance of the friends. I'm not by a django
computer right now
to figure it out but friends and friends2 could be added together to
pass one variable.

On Dec 22, 10:10 am, kev  wrote:
> Hello,
> Im reading a django book and it adds friends to user authentication
> system by making:
>
> (was .96)
>
> class Friendship(models.Model):
>   from_friend = models.ForeignKey(
>     User, related_name='friend_set'
>   )
>   to_friend = models.ForeignKey(
>     User, related_name='to_friend_set'
>   )
>   def __str__(self):
>     return '%s, %s' % (
>       self.from_friend.username,
>       self.to_friend.username
>     )
>   class Admin:
>     pass
>   class Meta:
>     unique_together = (('to_friend', 'from_friend'), )
>
> But for this to work, you have to add friendship both ways. Ex/ user1 -> 
> user2 and user2 -> user1 which means almost duplicate entries in
>
> this model. And anytime you modify one friendship, you have to do the
> same to the other one.
>
> Is there a better way to do this so that only one entry exists in the
> db? Any suggestions are welcome!
>
> Kevin
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models - newbie question

2008-06-07 Thread Alex Koshelev

Hmm..

def __unicode__( self ):
   return "%s" % self.team1 # if Teams model has its own __unicode__
method

On Jun 7, 5:34 pm, nikosk <[EMAIL PROTECTED]> wrote:
> Hi all
>
> Does anyone know how to do something like this :
>
> class Game(models.Model):
> team1 = models.ForeignKey(Teams, related_name=u'team_home')
> team2 = models.ForeignKey(Teams , related_name=u'team_away')
> round = models.ForeignKey(Round)
> game_date = models.DateField()
> def __unicode__(self):
> return Teams.objects.filter(self.team1)    DOES NOT
> WORK
>
> Basically I want __unicode__ to return Teams.name based on the foreign
> key reference
>
> thanks in advance
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models - newbie question

2008-06-07 Thread Sebastian Bauer
ups i think

return Teams.objects.get(self.team1_id).name

will be better :)


Sebastian Bauer pisze:
> try this:
>
> return Teams.objects.get(self.team1).name
>
>
> nikosk pisze:
>   
>> Hi all
>>
>> Does anyone know how to do something like this :
>>
>> class Game(models.Model):
>> team1 = models.ForeignKey(Teams, related_name=u'team_home')
>> team2 = models.ForeignKey(Teams , related_name=u'team_away')
>> round = models.ForeignKey(Round)
>> game_date = models.DateField()
>> def __unicode__(self):
>> return Teams.objects.filter(self.team1)    DOES NOT
>> WORK
>>
>> Basically I want __unicode__ to return Teams.name based on the foreign
>> key reference
>>
>> thanks in advance
>>
>>
>>
>> 
>>   
>> 
>
> >
>
>   

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models - newbie question

2008-06-07 Thread Sebastian Bauer

try this:

return Teams.objects.get(self.team1).name


nikosk pisze:
> Hi all
>
> Does anyone know how to do something like this :
>
> class Game(models.Model):
> team1 = models.ForeignKey(Teams, related_name=u'team_home')
> team2 = models.ForeignKey(Teams , related_name=u'team_away')
> round = models.ForeignKey(Round)
> game_date = models.DateField()
> def __unicode__(self):
> return Teams.objects.filter(self.team1)    DOES NOT
> WORK
>
> Basically I want __unicode__ to return Teams.name based on the foreign
> key reference
>
> thanks in advance
>
>
>
> >
>
>   

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django models

2007-05-28 Thread Lic. José M. Rodriguez Bacallao
So, if I add a ForeignKey field to my model it simply add a
"related_model_id" column to my table, let me ask something, how django
enforce that when I add a repeated value to that field it will an error, I
mean, a foreign key value that does not exist in the original table in a one
to many relationship?

On 5/28/07, Marc Fargas <[EMAIL PROTECTED]> wrote:
>
>
> Hi Jos�,
> As the documentation says, the best alternative right now is to set a
> ForeignKey from one of the models to the other, on which you should
> place the ForeignKey really depends on every specific case, normaly it
> should go to the one that "cannot live with the other" (hence, the
> dependent one).
>
> ForeignKey simply adds a "related_model_id" column to hold the id of the
> other model and both models get the appropiate attributes/methods to
> find their relatives.
>
> Hope this helps,
> Marc
>
> El lun, 28-05-2007 a las 11:45 -0400, Lic. Jos� M. Rodriguez Bacallao
> escribi�:
> > Hi every one, first of all, sorry about my english, it's not so good
> > but I'm still learning. Well, I'm new to django and right now I come
> > from zope (2/3) and plone. I find django very exciting but I got a
> > little problem, how can I specify a Generalization/Especialization
> > relation in django, I mean, the better way. Until now, I specify it by
> > a OneToOne relationship but reading the documentation about models I
> > saw that the semantic of this relationship will change, so, right now,
> > I don't know what to do to be forward compatible, anyone can help me?
> >
> > --
> > Lic. Jos� M. Rodriguez Bacallao
> > Informatics Science University
> > Habana-Cuba.
> > >
>
> >
>


-- 
Lic. José M. Rodriguez Bacallao
Informatics Science University
Habana-Cuba.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django models

2007-05-28 Thread Marc Fargas

Hi Jos�,
As the documentation says, the best alternative right now is to set a
ForeignKey from one of the models to the other, on which you should
place the ForeignKey really depends on every specific case, normaly it
should go to the one that "cannot live with the other" (hence, the
dependent one).

ForeignKey simply adds a "related_model_id" column to hold the id of the
other model and both models get the appropiate attributes/methods to
find their relatives.

Hope this helps,
Marc

El lun, 28-05-2007 a las 11:45 -0400, Lic. Jos� M. Rodriguez Bacallao
escribi�:
> Hi every one, first of all, sorry about my english, it's not so good
> but I'm still learning. Well, I'm new to django and right now I come
> from zope (2/3) and plone. I find django very exciting but I got a
> little problem, how can I specify a Generalization/Especialization
> relation in django, I mean, the better way. Until now, I specify it by
> a OneToOne relationship but reading the documentation about models I
> saw that the semantic of this relationship will change, so, right now,
> I don't know what to do to be forward compatible, anyone can help me? 
> 
> -- 
> Lic. Jos� M. Rodriguez Bacallao
> Informatics Science University
> Habana-Cuba.
> > 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models to SqlAlchemy models | preliminary implementation

2007-04-09 Thread limodou

On 4/10/07, Norjee <[EMAIL PROTECTED]> wrote:
>
> Quite often there has been talk about using SqlALchemy in Django, but
> as far as I'm aware there is no implementation yet.
>
> For me, replacing Django's model is definitely too ambitious, so I
> tried the next best thing, use Django's model declaration to create a
> SqlAlchemy binding. For most of the (read my) use cases, this works.
> As my main interest in SqlAlchemy is to use its more advanced query
> syntax, it is sufficient for me. One notable downside is that it adds
> a little overhead, instead of one model representation you end up with
> the, the Django one and the SqlAlchemy one.. But so be it..
>
> Anyway the first steps can be found at 
> http://jeroen.concept-q.com/projects/djangoalchemy/
> Any comments are welcome. (Though, as I mentioned in the readme as
> well.. I'll be rather busy and probably slow to respond.. so be it..)
>
Great!

-- 
I like python!
UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models, detect whether value comes from db, or has explicitly been supplied.

2007-03-15 Thread Norjee

I now sort of do what you proposed. I override the init. But for the
attributes that I want to keep track of I create create a property.
Then it's a matter of counting how often it has been accessed. Now I
just need inherit from both Model and DateTimeFieldHelper :)

---
_magic_dt_create_counter = {}
class DateTimeFieldHelper(object):
def __init__(self, *args, **kwargs):
global _magic_dt_create_counter
#print "init me!"
self._magic_dt_fields = {}
super(DateTimeFieldHelper, self).__init__(*args, **kwargs)
c = str(self.__class__)
if c not in _magic_dt_create_counter:
#print "Enhanceing %s", c
_magic_dt_create_counter[c] = 1
opts = self._meta
for f in opts.fields:
if isinstance(f, DateTimeField):
setattr(DateTimeFieldHelper , f.attname,
property(partial(_get_magic_dt_field, dt_field=f.attname),
partial(_set_magic_dt_field, dt_field=f.attname)))

# when supplied via kwargs, set to 1..
opts = self._meta
for f in opts.fields:
if isinstance(f, DateTimeField):
if f.attname in kwargs:
self._magic_dt_fields[f.attname] =
(kwargs[f.attname] ,1)

def _get_magic_dt_field(self, dt_field):
#print "get field: %s" %dt_field
return self._magic_dt_fields[dt_field][0] if dt_field in
self._magic_dt_fields else None

def _set_magic_dt_field(self, val, *args, **kwargs):
dt_field = kwargs["dt_field"]
#print "set field: %s" %dt_field
if dt_field in self._magic_dt_fields:
count = self._magic_dt_fields[dt_field][1] + 1
#print "%s has been set %s times now to %s" %
(dt_field,count,val)
else:
count = 0
self._magic_dt_fields[dt_field] = [val , count]
---

This is my new DateTimeField:

---
class DateTimeField(DateTimeField):
def __init__(self, verbose_name=None, name=None, auto_now=False,
auto_now_add=False, auto_override=False, **kwargs):
self.auto_now, self.auto_now_add, self.auto_override =
auto_now, auto_now_add, auto_override
if (auto_now or auto_now_add) and not auto_override:
kwargs['editable'] = False
kwargs['blank'] = True
Field.__init__(self, verbose_name, name, **kwargs)


def pre_save(self, model_instance, add):
if (not self.auto_override) and (self.auto_now or
(self.auto_now_add and add)):
value = datetime.datetime.now()
elif self.auto_override and (self.auto_now):
# somehow set currenttime if no time has explicitly been
set
# the somehow has been solved... be scared, very
hackish
if self.attname in model_instance._magic_dt_fields and
model_instance._magic_dt_fields[self.attname][1] >= 1:
# value has been explicitly set
#print "Value for %s has been set %s time" %
(self.attname, model_instance._magic_dt_fields[self.attname][1])
value = super(DateField,
self).pre_save(model_instance, add)
else:
# no value is set, use now
value = datetime.datetime.now()
else:
value = super(DateField, self).pre_save(model_instance,
add)
setattr(model_instance, self.attname, value)
return value
---

It all is very hackish, simply forcing myself to set the correct date
on an update would have been simpler :)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models, detect whether value comes from db, or has explicitly been supplied.

2007-03-15 Thread Norjee

I now sort of do what you proposed. I override the init. But for the
attributes that I want to keep track of I create create a property.
Then it's a matter of counting how often it has been accessed. Now I
just need inherit from both Model and DateTimeFieldHelper :)

---
_magic_dt_create_counter = {}
class DateTimeFieldHelper(object):
def __init__(self, *args, **kwargs):
global _magic_dt_create_counter
#print "init me!"
self._magic_dt_fields = {}
super(DateTimeFieldHelper, self).__init__(*args, **kwargs)
c = str(self.__class__)
if c not in _magic_dt_create_counter:
#print "Enhanceing %s", c
_magic_dt_create_counter[c] = 1
opts = self._meta
for f in opts.fields:
if isinstance(f, DateTimeField):
exec "DateTimeFieldHelper.%s =
property(partial(_get_magic_dt_field, dt_field=f.attname),
partial(_set_magic_dt_field, dt_field=f.attname))" % f.attname

# when supplied via kwargs, set to 1..
opts = self._meta
for f in opts.fields:
if isinstance(f, DateTimeField):
if f.attname in kwargs:
self._magic_dt_fields[f.attname] =
(kwargs[f.attname] ,1)

def _get_magic_dt_field(self, dt_field):
#print "get field: %s" %dt_field
return self._magic_dt_fields[dt_field][0] if dt_field in
self._magic_dt_fields else None

def _set_magic_dt_field(self, val, *args, **kwargs):
dt_field = kwargs["dt_field"]
#print "set field: %s" %dt_field
if dt_field in self._magic_dt_fields:
count = self._magic_dt_fields[dt_field][1] + 1
#print "%s has been set %s times now to %s" %
(dt_field,count,val)
else:
count = 0
self._magic_dt_fields[dt_field] = [val , count]
---

This is my new DateTimeField:

---
class DateTimeField(DateTimeField):
def __init__(self, verbose_name=None, name=None, auto_now=False,
auto_now_add=False, auto_override=False, **kwargs):
self.auto_now, self.auto_now_add, self.auto_override =
auto_now, auto_now_add, auto_override
if (auto_now or auto_now_add) and not auto_override:
kwargs['editable'] = False
kwargs['blank'] = True
Field.__init__(self, verbose_name, name, **kwargs)


def pre_save(self, model_instance, add):
if (not self.auto_override) and (self.auto_now or
(self.auto_now_add and add)):
value = datetime.datetime.now()
elif self.auto_override and (self.auto_now):
# somehow set currenttime if no time has explicitly been
set
# the somehow has been solved... be scared, very
hackish
if self.attname in model_instance._magic_dt_fields and
model_instance._magic_dt_fields[self.attname][1] >= 1:
# value has been explicitly set
#print "Value for %s has been set %s time" %
(self.attname, model_instance._magic_dt_fields[self.attname][1])
value = super(DateField,
self).pre_save(model_instance, add)
else:
# no value is set, use now
value = datetime.datetime.now()
else:
value = super(DateField, self).pre_save(model_instance,
add)
setattr(model_instance, self.attname, value)
return value
---

It all is very hackish, simply forcing myself to set the correct date
on an update would have been simpler :)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models, detect whether value comes from db, or has explicitly been supplied.

2007-03-14 Thread Malcolm Tredinnick

On Thu, 2007-03-15 at 08:37 +1100, Malcolm Tredinnick wrote:
> On Wed, 2007-03-14 at 20:26 +, Norjee wrote:
> > Imagine the following model:
> > 
> > class Article(models.Model):
> > title = models.IntegerField()
> > 
> > Then when you do case 1):
> > art = Article.objects.get(pk=1)
> > art.title = "New title"
> > art.save()
> > 
> > or case 2):
> > art = Article.objects.get(pk=1)
> > art.save()
> > 
> > Is there a way that the model, before saving, knows whether the title
> > (or any other field) has been reassigned? I need to know because for a
> > datefield I want to use now if no explicit date is given, otherwise
> > the given date.
> 
> There's no one-line method, but it's pretty easy to do: write a custom
> save() method on the Article class that retrieves the instance again and
> compares the fields. Something like
> 
> def save(self):
> if self.id:
> original = Article.objects.get(id=self.id)
> # Compare fields you care about
> super(Article, self).save()

It just occurred to me that there's another way to do this if you're
going to need it fairly often...

Write your own __init__() method on the Article class and make sure you
call Model.__init__ (or super(Article, self).__init__) as the very first
thing. The Model __init__ will initialise your class by loading any data
into the attributes. Then your own __init__ code can copy those original
values to another attribute somewhere in the object. Inside your save()
method, you compare the attributes you are saving to the ones you copied
aside in the __init__ method to work out any differences.

Normally we don't need to write __init__ methods on models, so I wasn't
thinking along these lines. Whilst pushing the vacuum cleaner around the
living room just now I realised I'd missed something obvious.

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models, detect whether value comes from db, or has explicitly been supplied.

2007-03-14 Thread Norjee

Thanks, I was hoping I was overlooking some Django internals, but
apparently not ;) I'll just stick to using two queries.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models, detect whether value comes from db, or has explicitly been supplied.

2007-03-14 Thread Rubic

Assuming you've got a 'mydate' attribute:

  mydate = models.DateField(null=True)

You can conditionally assign it if null:

  import datetime
  art = Article.objects.get(pk=1)
  if not art.mydate:
  art.mydate = datetime.date.today()
  art.save()

--
Jeff Bauer
Rubicon, Inc.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django models, detect whether value comes from db, or has explicitly been supplied.

2007-03-14 Thread Malcolm Tredinnick

On Wed, 2007-03-14 at 20:26 +, Norjee wrote:
> Imagine the following model:
> 
> class Article(models.Model):
> title = models.IntegerField()
> 
> Then when you do case 1):
> art = Article.objects.get(pk=1)
> art.title = "New title"
> art.save()
> 
> or case 2):
> art = Article.objects.get(pk=1)
> art.save()
> 
> Is there a way that the model, before saving, knows whether the title
> (or any other field) has been reassigned? I need to know because for a
> datefield I want to use now if no explicit date is given, otherwise
> the given date.

There's no one-line method, but it's pretty easy to do: write a custom
save() method on the Article class that retrieves the instance again and
compares the fields. Something like

def save(self):
if self.id:
original = Article.objects.get(id=self.id)
# Compare fields you care about
super(Article, self).save()

The reason this can't really be done any more simply than that is that
the attributes on an Article instance are just normal Python attributes
-- there is nothing Field-like about them until you do the saving.
Python has no automatic way to tell if a class's attributes have changed
between two points in time.

Reagrds,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Models, DRY, Scalability

2006-08-22 Thread Sean Perry

bayerj wrote:
> As soon as I change my database schema, I have several possibilites to
> get my app up again:
> (a) Change the model. Then drop the current db schema, fire up the new
> one. Drawback: I lose my data.
> (b) Change the model and change the schema manually. Drawback: I am
> repeating myself.
> (c) Make everything right from the start. Drawback: Can only be reached
> asymptotical. (I won't argue about that :)
> 

I have just been dumping the data to a sql file, fixing for the new 
fields and using django initial sql support (myapp/sql/model.sql) to 
import the data each time. Works, is relatively easy and lets me twiddle 
and experiment.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Django Models, DRY, Scalability

2006-08-21 Thread bayerj

This seems very promising to me. Although I personally would be more
comfortable with sql being the root of datastructures, this would be
against django's philosophy.

I'm looking forward to the implementation!


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Re: Django Models, DRY, Scalability

2006-08-20 Thread James Bennett

On 8/20/06, Todd O'Bryan <[EMAIL PROTECTED]> wrote:
> There's a Google Summer of Code project going on at the moment to
> support model evolution throughout a project's development. I haven't
> played with it, but I've heard it's coming along.

Actually, we've got a new tune: there's a *finished* Summer of Code
project for it, but we haven't yet had time to review the code
produced.

Hopefully within the week we'll have the schema evolution code posted
somewhere public, though, so interested users can grab it and play
around with it.

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Django Models, DRY, Scalability

2006-08-20 Thread Todd O'Bryan

On Sun, 2006-08-20 at 09:43 -0700, bayerj wrote:
> As soon as I change my database schema, I have several possibilites to
> get my app up again:
> (a) Change the model. Then drop the current db schema, fire up the new
> one. Drawback: I lose my data.
> (b) Change the model and change the schema manually. Drawback: I am
> repeating myself.
> (c) Make everything right from the start. Drawback: Can only be reached
> asymptotical. (I won't argue about that :)

There's a Google Summer of Code project going on at the moment to
support model evolution throughout a project's development. I haven't
played with it, but I've heard it's coming along.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Django Models, DRY, Scalability

2006-08-20 Thread Maciej Bliziński

On Sun, 2006-08-20 at 09:43 -0700, bayerj wrote:
> (b) Change the model and change the schema manually. Drawback: I am
> repeating myself.

Personally, I prefer this method. Yes, I am repeating myself, but I'm
still saving time by not re-importing or re-entering the data. At first
I didn't like it, but the only real problem was to memorize the ALTER
TABLE syntax.

-- 
Maciej Bliziński
http://automatthias.wordpress.com


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Django Models, DRY, Scalability

2006-08-20 Thread Antonio Cavedoni

Hi Justin,

On 20 Aug 2006, at 18:43, bayerj wrote:
> As soon as I change my database schema, I have several possibilites  
> to get my app up again:
> (a) Change the model. Then drop the current db schema, fire up the  
> new one. Drawback: I lose my data.
> (b) Change the model and change the schema manually. Drawback: I am  
> repeating myself.
> (c) Make everything right from the start. Drawback: Can only be  
> reached asymptotical. (I won't argue about that :)

There has been lots of discussion about this very issue in the past  
few months, the situation you describe is what all of us have to deal  
with at the moment. The discussion has converged on this wiki page,  
where all the proposals have been argued:

  http://code.djangoproject.com/wiki/SchemaEvolution

There is a Google Summer of Code project to implement the proposals  
on that wiki page, mentored by Kenneth Gonsalves and implemented by  
Derek Anderson:

  http://code.google.com/soc/django/appinfo.html?csaid=CE83CE9BB3C461B3

A branch for working on schema evolution has been created by Jacob  
about one month ago, but no commit have been yet performed on it  
(that I know of, at least):

  http://code.djangoproject.com/browser/django/branches/schema-evolution

I am not aware of the status of the schema evolution implementation  
at the moment, but am very looking forward to it.

Cheers.
-- 
Antonio



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Django models question

2006-06-02 Thread Guillermo Fernandez Castellanos

I'm a beginner, but I would do like this:

class Reservation(models.Model):
properties=model.CharField(maxlength=7,primary_key=True)

class Restaurant(models.Model):
name=models.CharField(maxlength=30,primary_key=True)
reservations=models.ForeignKey(Reservation)

class Theater(models.Model):
name=models.CharField(maxlength=30,primary_key=True)
reservations=models.ForeignKey(Reservation)

class Hotel(models.Model):
name=models.CharField(maxlength=30,primary_key=True)
reservations=models.ForeignKey(Reservation)

Use ForeignKey or ManyToMany as you need.

Enjoy,

G

On 6/2/06, Cornel Nitu <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> My application have three main models: Restaurant, Hotel, Theather. The
> fourth model is Reservation. I don't figure out to link the Reservation
> with the others, because everyone needs a reservation. :)
>
> PS. I don't want to duplicate the attributes/methods from the
> Reservation.
>
> Thanks
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---