Re: Seeking professional help for frontend design for a small django project

2018-02-27 Thread Andy
Whats in it for the potetial frontnd developer?
Money? Just fame?
How many pages are you talking about?


Am Dienstag, 27. Februar 2018 00:04:45 UTC+1 schrieb cjwalter:
>
> Hi everybody
>
> I’ve started a small django website which is up and running but could 
> benefit from some frontend polish (bootstrap3). As I need to launch it by 
> end of this week this is kind of time critical, but I assume for someone 
> who is specializing in this kind of work it will take a few hours only. 
>
> We shall communicate via skype with screen sharing and you will get a full 
> copy of the django project including a database dump to load it at your 
> site. Please contact me via eMail (cjwalt...@gmail.com )
>
> Best regards
>
> cj
>
>

-- 
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/b2fcda68-29c1-44b0-8c56-b9854fe6f259%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: autocomplete

2018-02-27 Thread Andy
for any more complicated admin autocompletes or stuff in the frontend use 
djang-select2

Am Montag, 26. Februar 2018 18:55:15 UTC+1 schrieb Mafabi Emmanuel:
>
> how do i design an autocomplete in django 2.0
>
>
>

-- 
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/bddebd4a-0dcb-478b-ab4b-9536f77ffc81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Is there a way to make a field both foreignKey or allow user to fill it in themself?

2018-02-27 Thread Alexander Joseph
Is there a way to make a form field or model field either a foreign key 
reference or allow the user to fill in something themselves? I'm making a 
fixed assets app and each fixed asset has an owner field, which I would 
like to assign to an app user if possible, and if not possible be able to 
fill in a name myself.

Thanks

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


What happened to CollapsedFieldsets.js?

2018-02-27 Thread Alan
Hi there,

Well, I used that like 8 years ago. Just wondering what's the current
solution for Django 2.0 if one want to collapse fields in forms.

Thanks in advance,

Alan

-- 
I'll cycle across Britain in 2018 for a charity, would you consider
supporting my cause? http://uk.virginmoneygiving.com/AlanSilva
Many thanks!
--
Alan Wilter SOUSA da SILVA, DSc
Senior Bioinformatician, UniProt
European Bioinformatics Institute (EMBL-EBI)
European Molecular Biology Laboratory
Wellcome Trust Genome Campus
Hinxton
Cambridge CB10 1SD
United Kingdom
Tel: +44 (0)1223 494588

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


Re: autocomplete

2018-02-27 Thread Maurizio B.
Django-autocomplete-light is probably your best option. We have used it in 
a couple of projects and it's customisable to a certain extent, and well 
maintained.

On Monday, February 26, 2018 at 6:55:15 PM UTC+1, Mafabi Emmanuel wrote:
>
> how do i design an autocomplete in django 2.0
>
>
>

-- 
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/dc8265a4-b7fb-4be2-a5a0-2b8b84909ab9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Channels 1.x

2018-02-27 Thread nferrari
Hello,

I'm using django-channels for some months and I'm observing a behaviour for 
which I don't know if it's a normal one, or a misconfiguration from my side.
Here is my pretty simple consumer :

# Connected to websocket.connect
@channel_session_user_from_http
def ws_task_connect(message):
if isinstance(message.user, AnonymousUser):
message.reply_channel.send({"close": True})
else:
# Accept connection
message.reply_channel.send({"accept": True})
# Add them to the right group
Group("task-%d" % message.user.pk).add(message.reply_channel)
refresh_current_tasks(message.user, send_if_empty=False)

# Connected to websocket.disconnect
@enforce_ordering
@channel_session_user
def ws_task_disconnect(message):
Group("task-%d" % message.user.pk).discard(message.reply_channel)

It does work but if my user does refresh the page, I see a new entry in the 
session table (django_session). In other terms, if my user browse 20 
different pages in his administration panel, I'll have 21 entries in the 
django_session table (1 session created by the native Django 
SessionMiddleware, 20 for every WebSocket created by browsing the 20 
pages). Is it normal or shouldn't this by reduced to 2 entries?

For information, upgrading to django-channels 2 is not yet an option for 
this project.

Kind regards,

-- 
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/160e0c3b-c74e-4683-acf6-a882716b9c5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels 1.x

2018-02-27 Thread Andrew Godwin
Yes, there is one session made per connection. They should expire and get
cleaned up like normal HTTP sessions if you run the session cleanup in
Django (or use backends that auto-cleanup)

Andrew

On Tue, Feb 27, 2018 at 11:00 AM, nferrari 
wrote:

> Hello,
>
> I'm using django-channels for some months and I'm observing a behaviour
> for which I don't know if it's a normal one, or a misconfiguration from my
> side.
> Here is my pretty simple consumer :
>
> # Connected to websocket.connect
> @channel_session_user_from_http
> def ws_task_connect(message):
> if isinstance(message.user, AnonymousUser):
> message.reply_channel.send({"close": True})
> else:
> # Accept connection
> message.reply_channel.send({"accept": True})
> # Add them to the right group
> Group("task-%d" % message.user.pk).add(message.reply_channel)
> refresh_current_tasks(message.user, send_if_empty=False)
>
> # Connected to websocket.disconnect
> @enforce_ordering
> @channel_session_user
> def ws_task_disconnect(message):
> Group("task-%d" % message.user.pk).discard(message.reply_channel)
>
> It does work but if my user does refresh the page, I see a new entry in
> the session table (django_session). In other terms, if my user browse 20
> different pages in his administration panel, I'll have 21 entries in the
> django_session table (1 session created by the native Django
> SessionMiddleware, 20 for every WebSocket created by browsing the 20
> pages). Is it normal or shouldn't this by reduced to 2 entries?
>
> For information, upgrading to django-channels 2 is not yet an option for
> this project.
>
> Kind regards,
>
> --
> 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/160e0c3b-c74e-4683-acf6-a882716b9c5b%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/CAFwN1uqkAFROigauWNObxvkYd5cEvhYRDAYt2Ut8HNbcshTf_g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Why doesn't Django support managing Raw SQL changes using migration system like models

2018-02-27 Thread cmp
I have an problem that I wanted to solve recently using a Postgres Trigger 
+ Procedure that I do not want to do via Signals or within Python itself.

I want to make a log which when an entry is created the result is applied 
to a row. We need the log to be the source of truth and I don't want to 
write a whole async system using something like Kafka or whatever everyone 
recommends.

The issue here is that I need to iterate on the procedure which updates the 
rows as features come along and make it easy for other developers to 
find/read/etc.

Django only allows storing things like this as RawSql migration commands 
inside the migrations folder but this App already has 76 migrations and I 
think it's probably unreasonable for me to assume a normal django developer 
will think to read all those migrations without running in to some problem 
with my triggers. Not to mention the main block of sql will need to be copy 
and pasted between changes to new migrations... etc.

This seems like something the migration system should support somehow.

I found a package which seems to do this, but it appears unmaintained 
(little to no activity): https://github.com/klichukb/django-migrate-sql

I think it'd be a nice feature for Django to support maintaining a set of 
Raw SQL via the migration system so more advanced features of databases can 
be used.

For instance in Postgres setting up other things like full text search and 
special search indexes were difficult in 1.8. I realize it's easier since 
1.10 to add a full text search index, but adding that feature is much more 
difficult than the RawSQL migrations we did to implement adding the index 
before.

Making it easy to manage triggers and procedures via the migration system 
is very difficult, but I think supporting RawSQL items which are managed 
via migrations would be relatively easy to implement and add a lot of value.

I'm posting this for two reasons: 1) I think it's a good idea and 2) to let 
others show me where I'm missing something or why this wouldn't be a good 
fit for 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/8043d044-3f7c-4bd2-bdc4-c504faf5120b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Static/constant dictionary for get_initial or get_form_kwargs

2018-02-27 Thread Bob Glassett
Hello, 

Trying to bring a django app into production, and I ran into a real 
headscratcher.

I have a Class based view inherited from create.  When the page reloads, 
after validation, I check the initial dictionary for a field's value to 
fill in the queryset for a different field.

I'm getting sporadic errors about one of the fields not found in the 
initial object.  When I looked closer into the problem, the initial 
dicitonary matched a form for a totally different model.

If I need to pre-populate the initial dictionary, I override the 
get_initial and return the dictionary that I want.  I am not setting 
initial= in the class definition.  Is this the right way to do this task?

I am concerned about a static initial dictionary sticking around.  The base 
edit class returns a copy of the initial dictionary, but if the initial 
dicitonary somehow has invalid values in it, I could be seeing this for all 
my forms.

This is what I did for the initial dictionary:

class UserCreateView(AdminCreateView):

model=User

success_url='/portal/accounts/list'

form_class=PortalUserForm 



def get_form_kwargs(self):

kwargs = super(UserCreateView, self).get_form_kwargs()

kwargs.update({'request' : self.request})

return kwargs 



def get_initial(self):

return {}


On a ModelForm (unrelated to the form/model above) I was trying to access 
the self.initial for a particular field, which threw a Key exception.  The 
initial dictionary passed down on the yellow screen did not match the form 
or data for the view at all.


kwargs:  



{'initial': {'agency': ,
 'canEnterMealCounts': False,
 'canManageCalendar': True,
 'canManageCustomerAllergies': True,
 'canManageFieldTrips': True,
 'canManageSocializations': True,
 'canManageSpecialOrders': True,
 'canManageSupplies': False,
 'canPrintMenus': True,
 'chefablesUser': False,
 'location': ,
 'phone': PhoneNumber(country_code=1, national_number=2018158136, 
extension=None, italian_leading_zero=None, number_of_leading_zeros=None, 
country_code_source=1, preferred_domestic_carrier_code=None)},
 'instance': None,
 'prefix': None}


I have no idea where that initial dictionary came from.  My get_form_kwargs 
looks like this:


def get_form_kwargs(self):

kwargs = super(PendingLabelsCreateView, self).get_form_kwargs()

kwargs.update({'user': self.request.user})

return kwargs


The direct ancestor doesn;'t have get_form_kwargs defined, and that is 
defined as such:


class AdminCreateView(LoginRequiredMixin, UserPassesTestMixin, CreateView):


I need to understand where that initial value came from and determine if I 
have static values where I don't want them.


Thanks in advance



-- 
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/db24def3-f8cc-4954-bbd3-72b6ed3fa0d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to make a field both foreignKey or allow user to fill it in themself?

2018-02-27 Thread Mike Dewhirst

On 28/02/2018 1:26 AM, Alexander Joseph wrote:
Is there a way to make a form field or model field either a foreign 
key reference or allow the user to fill in something themselves? I'm 
making a fixed assets app and each fixed asset has an owner field, 
which I would like to assign to an app user if possible, and if not 
possible be able to fill in a name myself.


Yes. Make the ForeignKey in the model null=True and blank=True so it can 
exist all alone. Then you can limit_choices_to whatever whatever suits 
your requirements ...


https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to

hth
Mike




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

Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/98c44317-0993-4d41-9d25-33f8a9821dce%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/5b6e5c4d-5c69-ecb4-db11-d924fdd653e1%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to make a field both foreignKey or allow user to fill it in themself?

2018-02-27 Thread Alexander Joseph
Sorry, I think my question was confusing. What I want to do is allow the 
user to either select a user from a drop down list of users from the 
ForeignKey in the Users model, or if there is not a user suitable to select 
in the drop down, they can manually type in a name themselves.

Thanks for your reply



On Tuesday, February 27, 2018 at 7:45:51 PM UTC-7, Mike Dewhirst wrote:
>
> On 28/02/2018 1:26 AM, Alexander Joseph wrote: 
> > Is there a way to make a form field or model field either a foreign 
> > key reference or allow the user to fill in something themselves? I'm 
> > making a fixed assets app and each fixed asset has an owner field, 
> > which I would like to assign to an app user if possible, and if not 
> > possible be able to fill in a name myself. 
>
> Yes. Make the ForeignKey in the model null=True and blank=True so it can 
> exist all alone. Then you can limit_choices_to whatever whatever suits 
> your requirements ... 
>
>
> https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to
>  
>
> hth 
> Mike 
>
>
> > 
> > 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...@googlegroups.com  
> > . 
> > To post to this group, send email to django...@googlegroups.com 
>  
> > . 
> > Visit this group at https://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/98c44317-0993-4d41-9d25-33f8a9821dce%40googlegroups.com
>  
> > <
> https://groups.google.com/d/msgid/django-users/98c44317-0993-4d41-9d25-33f8a9821dce%40googlegroups.com?utm_medium=email&utm_source=footer>.
>  
>
> > 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/dd78c8cf-1892-4740-b3cb-1e384b9bd788%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to get Foreign Key Objects programmatically?

2018-02-27 Thread Malik Rumi
Did you ever find an answer? If so, do you mind sharing it? Thanks.

On Sunday, October 29, 2017 at 9:33:10 AM UTC-7, rmschne wrote:
>
> I'm using Django as front end to a MySQL database. User interface is a 
> terminal program, not a web site.
>
> I've written a very simple generic function to edit the fields of one 
> record of a Django "object".  It works fine for editing editable fields. 
> User specifies which field, then is shown the current value, raw_input() 
> for the new value, then save() the record.
>
> For fields that connect to Foreign Keys, what I want to do is present to 
> user a simple list of Foreign Key records, from which the user will pick 
> the relevant ID.  I know, given a list and the ID, how to then edit the 
> record by doing a Django get(id=ID) on the Foreign Key table.  What I'm 
> having trouble doing is figuring how
>
> 1. Identify into a variable the name of the Foreign Key table/object
> 2. Then with that variable do a call to the relevant Foreign Key table, 
> e.g. ForeignKeyTable.objects.all()
>
> See code below for <===WHAT I DO NOT KNOW HOW TO DO IN CODE Below.  I 
> think I need some Django function that gives me the foreign key table in 
> some useable generic form.
>
> Hope all this makes sense. 
>
> --rms
>
> def EditDjangoObjectData(djangoobject,show=False,editonerecord=False):
> """
> EditDjangoObjectData()
> djangoojbect=a django object, e.g. a record in a table
> """
> print "\nToDo Note: This routine not yet working on fields with 
> foreign keys!"
> changelist=[]
> ok=True
> while ok:
> change=None
> fields = [(f.name, f.editable) for f in 
> djangoobject._meta.get_fields()]
> if show:
> print "\nfields:\n",fields
> print "django object:\n",djangoobject
> s="\nEditable Fields ('enter' to return): \n"
> fieldlist=[]
> for i in fields:
> if i[1]:   # only for 'editable' fields
> if i[0].lower() <> "id":
> s=s+i[0]+", "
> fieldlist.append(i[0])
> s=s+"DELETE or '?'"
> fieldok=False
> while not fieldok:
> fieldtochange=raw_input("Enter field name to change:\n"+s+": ")
> if not fieldtochange:
> return None
> elif fieldtochange.upper()=="DELETE":
> ans=raw_input("...Confirm DELETE by typing 'DELETE': ")
> try:
> if ans=="DELETE":
> rtn=djangoobject.delete()
> print "Deleted. ",rtn
> return rtn
> except:
> print "***DELETE Failed.",sys.exc_info()[0]
> ans=raw_input("Press 'Enter' to continue ... ")
> elif fieldtochange=="?":
> PrintObjectDetails(djangoobject)
> elif fieldtochange in fieldlist:
> fieldok=True
> else:
> print "\nError. ",fieldtochange,"is not in list. Try 
> again."
> print "Current Value of Field to 
> Change:",fieldtochange,"is:",getattr(djangoobject, fieldtochange)
> **
> ** In here add some code to show a list of the foreign key records for 
> user to select, e.g. ID, Description, 
> **for r in ForeignKey.objects.all():   <== WHAT I DO NOT KNOW HOW TO DO IN 
> CODE.
> **print i.id, i.description
> **ID=raw_input("Enter ID:)
> **foreignkeyobject=ForeignKey.objects.get(id=ID)<== WHAT I DO NOT KNOW 
> HOW TO DO IN CODE.
> ** ... then put that object into the relevant field 
> newvalue=raw_input("Enter New Value: ")
> change="changed ["+fieldtochange+"]"
> print "\nTo Save   :",djangoobject
> print "The Change:",change,"to",newvalue
> if not newvalue:
> return None
> elif newvalue.lower()=="none":
> newvalue=None
> elif newvalue.lower()=="true":
> newvalue==True
> elif newvalue.lower()=="false":
> newvalue=False
> setattr(djangoobject, fieldtochange, newvalue)
> try:
> djangoobject.save()
> print ": Success. Saved:",change,"to",newvalue
> print ": New Object:",djangoobject
> changelist.append(change)
> print "ChangeList:",changelist
> except:
> print "***Save Failed.",sys.exc_info()[0]
> ans=raw_input("Press 'Enter' to continue ... ")
> if editonerecord:
> ok=False
> return changelist
>
>

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

Re: Is there a way to make a field both foreignKey or allow user to fill it in themself?

2018-02-27 Thread Mike Dewhirst

On 28/02/2018 1:58 PM, Alexander Joseph wrote:
Sorry, I think my question was confusing. What I want to do is allow 
the user to either select a user from a drop down list of users from 
the ForeignKey in the Users model, or if there is not a user suitable 
to select in the drop down, they can manually type in a name themselves.


In the same field that would require a hack of the first water.  Way 
above my pay grade. For me, anything which equates an existing user 
object with a string typed in is likely to end in misery.


Otherwise a separate CharField for the typed in name and null=True and 
blank=True in the ForeignKey ought to work.


Mike



Thanks for your reply



On Tuesday, February 27, 2018 at 7:45:51 PM UTC-7, Mike Dewhirst wrote:

On 28/02/2018 1:26 AM, Alexander Joseph wrote:
> Is there a way to make a form field or model field either a foreign
> key reference or allow the user to fill in something themselves?
I'm
> making a fixed assets app and each fixed asset has an owner field,
> which I would like to assign to an app user if possible, and if not
> possible be able to fill in a name myself.

Yes. Make the ForeignKey in the model null=True and blank=True so
it can
exist all alone. Then you can limit_choices_to whatever whatever
suits
your requirements ...


https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to




hth
Mike


>
> 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...@googlegroups.com 
> .
> To post to this group, send email to django...@googlegroups.com

> .
> Visit this group at https://groups.google.com/group/django-users
.
> To view this discussion on the web visit
>

https://groups.google.com/d/msgid/django-users/98c44317-0993-4d41-9d25-33f8a9821dce%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/dd78c8cf-1892-4740-b3cb-1e384b9bd788%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/4facfe44-e50e-e7d4-e41a-1c82775a8f7f%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: How to get Foreign Key Objects programmatically?

2018-02-27 Thread Rob Schneider
Still a mystery to me.


--rms


> On 28 Feb 2018, at 03:22, Malik Rumi  wrote:
> 
> Did you ever find an answer? If so, do you mind sharing it? Thanks.
> 
>> On Sunday, October 29, 2017 at 9:33:10 AM UTC-7, rmschne wrote:
>> I'm using Django as front end to a MySQL database. User interface is a 
>> terminal program, not a web site.
>> 
>> I've written a very simple generic function to edit the fields of one record 
>> of a Django "object".  It works fine for editing editable fields. User 
>> specifies which field, then is shown the current value, raw_input() for the 
>> new value, then save() the record.
>> 
>> For fields that connect to Foreign Keys, what I want to do is present to 
>> user a simple list of Foreign Key records, from which the user will pick the 
>> relevant ID.  I know, given a list and the ID, how to then edit the record 
>> by doing a Django get(id=ID) on the Foreign Key table.  What I'm having 
>> trouble doing is figuring how
>> 
>> 1. Identify into a variable the name of the Foreign Key table/object
>> 2. Then with that variable do a call to the relevant Foreign Key table, e.g. 
>> ForeignKeyTable.objects.all()
>> 
>> See code below for <===WHAT I DO NOT KNOW HOW TO DO IN CODE Below.  I think 
>> I need some Django function that gives me the foreign key table in some 
>> useable generic form.
>> 
>> Hope all this makes sense. 
>> 
>> --rms
>> 
>> def EditDjangoObjectData(djangoobject,show=False,editonerecord=False):
>> """
>> EditDjangoObjectData()
>> djangoojbect=a django object, e.g. a record in a table
>> """
>> print "\nToDo Note: This routine not yet working on fields with 
>> foreign keys!"
>> changelist=[]
>> ok=True
>> while ok:
>> change=None
>> fields = [(f.name, f.editable) for f in 
>> djangoobject._meta.get_fields()]
>> if show:
>> print "\nfields:\n",fields
>> print "django object:\n",djangoobject
>> s="\nEditable Fields ('enter' to return): \n"
>> fieldlist=[]
>> for i in fields:
>> if i[1]:   # only for 'editable' fields
>> if i[0].lower() <> "id":
>> s=s+i[0]+", "
>> fieldlist.append(i[0])
>> s=s+"DELETE or '?'"
>> fieldok=False
>> while not fieldok:
>> fieldtochange=raw_input("Enter field name to change:\n"+s+": ")
>> if not fieldtochange:
>> return None
>> elif fieldtochange.upper()=="DELETE":
>> ans=raw_input("...Confirm DELETE by typing 'DELETE': ")
>> try:
>> if ans=="DELETE":
>> rtn=djangoobject.delete()
>> print "Deleted. ",rtn
>> return rtn
>> except:
>> print "***DELETE Failed.",sys.exc_info()[0]
>> ans=raw_input("Press 'Enter' to continue ... ")
>> elif fieldtochange=="?":
>> PrintObjectDetails(djangoobject)
>> elif fieldtochange in fieldlist:
>> fieldok=True
>> else:
>> print "\nError. ",fieldtochange,"is not in list. Try 
>> again."
>> print "Current Value of Field to 
>> Change:",fieldtochange,"is:",getattr(djangoobject, fieldtochange)
>> **
>> ** In here add some code to show a list of the foreign key records for user 
>> to select, e.g. ID, Description, 
>> **for r in ForeignKey.objects.all():   <== WHAT I DO NOT KNOW HOW TO DO IN 
>> CODE.
>> **print i.id, i.description
>> **ID=raw_input("Enter ID:)
>> **foreignkeyobject=ForeignKey.objects.get(id=ID)<== WHAT I DO NOT KNOW 
>> HOW TO DO IN CODE.
>> ** ... then put that object into the relevant field 
>> newvalue=raw_input("Enter New Value: ")
>> change="changed ["+fieldtochange+"]"
>> print "\nTo Save   :",djangoobject
>> print "The Change:",change,"to",newvalue
>> if not newvalue:
>> return None
>> elif newvalue.lower()=="none":
>> newvalue=None
>> elif newvalue.lower()=="true":
>> newvalue==True
>> elif newvalue.lower()=="false":
>> newvalue=False
>> setattr(djangoobject, fieldtochange, newvalue)
>> try:
>> djangoobject.save()
>> print ": Success. Saved:",change,"to",newvalue
>> print ": New Object:",djangoobject
>> changelist.append(change)
>> print "ChangeList:",changelist
>> except:
>> print "***Save Failed.",sys.exc_info()[0]
>> ans=raw_input("Press 'Enter' to continue ... ")
>> if editonerecord:
>> ok=False
>> return changelist
>> 
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "Django users" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic

Re: django mathfiters

2018-02-27 Thread Peter of the Norse
I would do
{% with a=42 c=b.value|default_if_none:0}

- Peter of the Norse

> On Feb 21, 2018, at 3:47 PM, Matthew Pava  wrote:
> 
> And how are you checking if it’s None?  I would do it like this:
> {% if c %}
> {{ a|add:c }}
> {% else %}
>   {{ a }}
> {% endif %}
>  
> From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
> Behalf Of sum abiut
> Sent: Wednesday, February 21, 2018 4:43 PM
> To: django-users@googlegroups.com
> Subject: Re: django mathfiters
>  
> Thanks for your response. Yes the value was actually None. how to i display 
> 42  instead of not displaying anything at all. I have try using the if 
> statement to check for the value of c if its None i just display the value of 
> a, and if is not None i add the values. But still its displaying nothing.
>  
> Thanks
>  
> On Thu, Feb 22, 2018 at 9:15 AM, Matthew Pava  wrote:
> Check the value of b.value.  Make sure it isn’t None.
>  
> From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
> Behalf Of sum abiut
> Sent: Wednesday, February 21, 2018 4:06 PM
> To: django-users@googlegroups.com
> Subject: django mathfiters
>  
>  
> Hi,
> How to you a zero in mathfilter
> for example, if the value of c is zero the total is not display. instead of 
> displaying 42 it display nothing.
>  
> {%for b in pay%}
> {% with a=42 c=b.value%}
>  {{ a|add:c }}
> {% endwith %}
> 

-- 
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/8C4DDEF6-9168-4181-B5DD-8E37AB487685%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.