Heroku Git Error
Hi everyone, It's a miracle I've gotten this far with the amount of knowledge that I don't have with coding, hosting, django, heroku, git etc. However, I've been using a heroku server to serve my website for the last couple of months and I've been able to do so without any issues. However, last week I was away from my office and i tried to make some changes to my site via a new machine, which I knew was a bad idea. I committed one change, never pushed it using "git push heroku master" and then deleted the change using git reset Now that I'm back in my office at my original machine, I'm having all sorts of issues and I cannot commit any changes or even hookup with git on the same page. When I try to push to heroku master I get: ![rejected] master --> master (non-fast forward) error: failed to push some refs to 'https://git.heroku... Updates were rejectred because the tip of your current batch is behind its remote counterpart. Integrate the remote changes (e.g. git pull) before pushing again okay- well that's all well and good, but I can't perform git pull, git fetch or anything along those lines either. I get: Permission denied (publickey) fatal could not read from repository Please make sure you have the correct access rights and the repository exists Please help! Thanks, Aaron -- 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/1ada81a0-3138-489d-b7b9-74b8c83e600a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Django template iterating through two dictionaries/variables
This is why i ask this group. Everyone helped out, but Nate's link pushed me in the right direction. Sometimes I don't even know what to ask stack overflow, but the google group always helps out. Thanks On Tuesday, August 30, 2016 at 11:28:37 AM UTC-5, Nate Granatir wrote: > > You could also just join the dicts before passing them to the template. It > looks like it's relatively straightforward (scores is just a list that > contains dicts of a 'Number' and a 'score', right?) Then you could turn > scores into a dict, assuming Numbers are unique: > > scores_new = {score['Number']:score['score'] for score in scores} > > And then update the persons dict to include the score: > for person in persons: > person.update({'score': scores_new.get(person['Number'])}) > > Then in your persons list in the template you'll just need to display > person.score. > > If you want to get really fancy (if, say, there's more than just a score > you need to pull from the dicts in scores) you can see how to merge two > lists of dicts on a common key here: > > http://stackoverflow.com/questions/5501810/join-two-lists-of-dictionaries-on-a-single-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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/49018a13-680a-4b6d-8d1e-be5c5444c2d9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Django template iterating through two dictionaries/variables
I hate to be thick but could you explain to me how to load the filters and also how the template should look with the updated function? Solving this will unlock a ton of functionality for my app. Thanks, Aaron On Aug 29, 2016 12:34 PM, "Asad Jibran Ahmed" <surfer...@gmail.com> wrote: > No problem. The most probable reason why you're getting the invalid filter > error is because you forgot to load the filters. > > Your explanation of the workflow is correct, with one small correction. > The template will handoff the search for the correct *Score* to the > filter function. Whatever the filter function returns will then be inserted > in place of the {scores|from_player:person} part in your template. One > way of getting the correct score would be to loop over the items in your > scores dictionary, and find the one where the identification numbers match. > One suggestion, instead of returning a dictionary from your filter > function, you should return the value you want to display. So maybe your > filter can look something like: > def get_score_for_person(scores, person): > for s in scores: > if s['Number'] == p.Number: >return s['Score'] > > > And you're right, maybe you can rename the filter to be > get_score_for_person if that is more clear for your application. > > On Monday, August 29, 2016 at 8:12:56 PM UTC+4, Aaron Weisberg wrote: >> >> Thanks Asad. Is that why I'm getting errors saying invalid filter name? >> >> Also I'm having a difficult time thinking my way through the workflow. >> I'm defining a new function that requires scores(my URL based dictionary) >> and person (my database dictionary). The function then asks to return the >> scores of the corresponding game number. Then the template is looking for >> the correct value in the scores dictionary that has the same Number >> identification as the existing person.Number? >> >> I think what is confusing me is the use of "player" in ludovics example >> >> Thanks >> >> Aaron >> >> On Aug 29, 2016 11:53 AM, "Asad Jibran Ahmed" <surf...@gmail.com> wrote: >> >>> No need to change the context, since the variable names the example here >>> uses are the same as your existing context. It should work as long as you >>> remember to {% load APPNAME %} your filters in the template first. >>> >>> >>> Asad Jibran Ahmed <surf...@gmail.com> >>> http://blog.asadjb.com >>> >>> On Mon, Aug 29, 2016 at 6:50 PM, Aaron Weisberg <aaron.m@gmail.com> >>> wrote: >>> >>>> Thanks ludovic, >>>> >>>> I'm trying to write that python code presently- would I have to also >>>> change the context? how would that look? >>>> >>>> Thanks >>>> >>>> On Fri, Aug 26, 2016 at 10:40 AM, ludovic coues <cou...@gmail.com> >>>> wrote: >>>> >>>>> You could write a filter [1]. It would be used like {{ >>>>> scores|from_player:person }} and look like that: >>>>> >>>>> def from_player (scores, player): >>>>> return scores[player.Number] >>>>> >>>>> You might want to adjust to your actual code, check that you got the >>>>> right arguments and that kind of things. >>>>> >>>>> [1] https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/ >>>>> >>>>> 2016-08-26 15:50 GMT+02:00 Aaron Weisberg <aaron.m@gmail.com>: >>>>> > I didn't really know how to label this question, but I think it's an >>>>> > interesting concept and I haven't seen a resolution anywhere else. >>>>> > >>>>> > I currently have two different dictionaries as context for a >>>>> template: >>>>> > >>>>> > Enter code here...context ={ >>>>> > 'person':person, >>>>> > 'scores':scores, >>>>> >} >>>>> > >>>>> > >>>>> > Each of these dictionaries has a common key (person.Number), >>>>> > (scores.Number), however the person dictionary is based off of a >>>>> model in my >>>>> > django database, while scores comes from a json feed that I parse >>>>> through: >>>>> > >>>>> > I currently run through a table in a template that looks like this: >>>>> >
Re: Django template iterating through two dictionaries/variables
Thanks Asad. Is that why I'm getting errors saying invalid filter name? Also I'm having a difficult time thinking my way through the workflow. I'm defining a new function that requires scores(my URL based dictionary) and person (my database dictionary). The function then asks to return the scores of the corresponding game number. Then the template is looking for the correct value in the scores dictionary that has the same Number identification as the existing person.Number? I think what is confusing me is the use of "player" in ludovics example Thanks Aaron On Aug 29, 2016 11:53 AM, "Asad Jibran Ahmed" <surfer...@gmail.com> wrote: > No need to change the context, since the variable names the example here > uses are the same as your existing context. It should work as long as you > remember to {% load APPNAME %} your filters in the template first. > > > Asad Jibran Ahmed <surfer...@gmail.com> > http://blog.asadjb.com > > On Mon, Aug 29, 2016 at 6:50 PM, Aaron Weisberg < > aaron.m.weisb...@gmail.com> wrote: > >> Thanks ludovic, >> >> I'm trying to write that python code presently- would I have to also >> change the context? how would that look? >> >> Thanks >> >> On Fri, Aug 26, 2016 at 10:40 AM, ludovic coues <cou...@gmail.com> wrote: >> >>> You could write a filter [1]. It would be used like {{ >>> scores|from_player:person }} and look like that: >>> >>> def from_player (scores, player): >>> return scores[player.Number] >>> >>> You might want to adjust to your actual code, check that you got the >>> right arguments and that kind of things. >>> >>> [1] https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/ >>> >>> 2016-08-26 15:50 GMT+02:00 Aaron Weisberg <aaron.m.weisb...@gmail.com>: >>> > I didn't really know how to label this question, but I think it's an >>> > interesting concept and I haven't seen a resolution anywhere else. >>> > >>> > I currently have two different dictionaries as context for a template: >>> > >>> > Enter code here...context ={ >>> > 'person':person, >>> > 'scores':scores, >>> >} >>> > >>> > >>> > Each of these dictionaries has a common key (person.Number), >>> > (scores.Number), however the person dictionary is based off of a model >>> in my >>> > django database, while scores comes from a json feed that I parse >>> through: >>> > >>> > I currently run through a table in a template that looks like this: >>> > >>> > Enter code here... >>> > >>> > >>> > Person >>> > Person Number >>> > First Name >>> > Last Name >>> > City >>> > Score >>> > >>> > >>> > >>> >{% for person in persons %} >>> > >>> > {{ person.Number }} >>> > {{ person.firstName }} >>> > >>> {{ >>> > person.lastName }} >>> > >>> {{ >>> > person.city }} >>> > >>> > ??'''scores.score1 goes here''' >>> > >>> > {% endfor %} >>> > >>> > >>> > >>> > What I'm trying to figure out to do is figure out how to get that final >>> > detail loaded into the table where we would find the score specific to >>> that >>> > person.Number. In other words how to go through my scores dictionary >>> in >>> > this template and find the corresponding score1 using the >>> person.Number from >>> > the other dictionary as the value. >>> > >>> > >>> > Let me know if you have any ideas. >>> > >>> > 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
Re: Django template iterating through two dictionaries/variables
Thanks ludovic, I'm trying to write that python code presently- would I have to also change the context? how would that look? Thanks On Fri, Aug 26, 2016 at 10:40 AM, ludovic coues <cou...@gmail.com> wrote: > You could write a filter [1]. It would be used like {{ > scores|from_player:person }} and look like that: > > def from_player (scores, player): > return scores[player.Number] > > You might want to adjust to your actual code, check that you got the > right arguments and that kind of things. > > [1] https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/ > > 2016-08-26 15:50 GMT+02:00 Aaron Weisberg <aaron.m.weisb...@gmail.com>: > > I didn't really know how to label this question, but I think it's an > > interesting concept and I haven't seen a resolution anywhere else. > > > > I currently have two different dictionaries as context for a template: > > > > Enter code here...context ={ > > 'person':person, > > 'scores':scores, > >} > > > > > > Each of these dictionaries has a common key (person.Number), > > (scores.Number), however the person dictionary is based off of a model > in my > > django database, while scores comes from a json feed that I parse > through: > > > > I currently run through a table in a template that looks like this: > > > > Enter code here... > > > > > > Person > > Person Number > > First Name > > Last Name > > City > > Score > > > > > > > >{% for person in persons %} > > > > {{ person.Number }} > > {{ person.firstName }} > > > {{ > > person.lastName }} > > > {{ > > person.city }} > > > > ??'''scores.score1 goes here''' > > > > {% endfor %} > > > > > > > > What I'm trying to figure out to do is figure out how to get that final > > detail loaded into the table where we would find the score specific to > that > > person.Number. In other words how to go through my scores dictionary in > > this template and find the corresponding score1 using the person.Number > from > > the other dictionary as the value. > > > > > > Let me know if you have any ideas. > > > > 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/d05c8fc4- > 706b-422b-bc11-b656f1950dea%40googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. > > > > -- > > Cordialement, Coues Ludovic > +336 148 743 42 > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Django users" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/django-users/UlgghbsoqYI/unsubscribe. > To unsubscribe from this group and all its topics, 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/CAEuG%2BTatGSwstRkfEDpZdeB6yMv2Bobia > Q_Zb3CEL7ZXr5kE-g%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/CAL5RJ55RzR6MuwXS-ARFKKDb948ijOW9jfp27Th76Xt006%3D_5g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: How to set up a form from an existing view
Thanks ludovic I'll try that. I have a very basic form question. What attribute gets posted in the .POST? Is that value? In input? Secondly, the default value in the function, is that a type like text or integer or is it just a place holder like "Chicago" or "2" Thanks On Aug 26, 2016 11:33 AM, "ludovic coues" <cou...@gmail.com> wrote: > First, your html is invalid. You can't put a whole form in a link. Nor > a button. You can remove the element and put the shiny class on > the input[type=submit] > > About your input[type=submit], I have some doubts about cross brother > compatibility of what you are trying to achieve. It would be either to > add an input[type=hidden] which the value {{games.roadTeam}}. This > will prevent you some headache if your code don't work under IE or Fx > or chrome or whatnot. > > About your question, > you can use the request argument, like this: > > if request.method == "POST": > request.POST.get("variable", "default_value") > > If you want to do something more complex than simply find which team > is chosen, you should create a form class. This will simplify data > handling. > > That being said, you are on a good start :) > > 2016-08-26 16:00 GMT+02:00 Aaron Weisberg <aaron.m.weisb...@gmail.com>: > > Good morning, > > > > I have been working on an app displaying some analytics and I want to > > incorporate some user feedback and I am having trouble figuring out how: > > > > I have a detail view: > > > > Enter code here... > > > > #views.py > > def detail(request, game_id): > > games = Game.objects.get(pk=game_id) > > context = { > > 'games':games} > > return render(request,'myapp/detail.html',context) > > > > Very simple with no form activity as of yet. > > > > My template currently shows a comparison between two properties set up > like: > > > > #detail.html > > > > > > > > > > > > > > {{ games.roadTeam }} > > {{ games.roadTeamWins}} - > {{ > > games.roadTeamLosses}} > > > > > > > > > > {{games.homeTeam }} > > {{ games.HomeTeamWins}} - > {{ > > games.HomeTeamLosses}} > > > > > > > > > > > > I would like to work backwards and turn this template into a form. > Would I > > be able to make it a form by adding a third div to each one of these > that is > > a button which sends the value of the variable back to the view? and > then > > how would I be able to process that in the view? > > Enter code here... > > > > > > method="post">{% > > csrf_token %} > > > > > style="width 100%"> > > > > > > I am not an expert when it comes to forms, so your assistance would be > > greatly appreciated. > > > > 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/0569cc00- > 30c1-4b14-b521-107e37149340%40googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. > > > > -- > > Cordialement, Coues Ludovic > +336 148 743 42 > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Django users" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/django-users/2pxh8Pmrfrg/unsubscribe. > To unsubscribe from this group and all its topics, 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/CAEuG%2BTZtE_QP3uq473HkW%2BRmYNtPrHV3XO%2B09PubC4sp5k- > H0A%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/CAL5RJ57pYTyBsgPmzvC8ryq8jWW-r6PsGTLL7cu8P8iMt7Y0ag%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
How to set up a form from an existing view
Good morning, I have been working on an app displaying some analytics and I want to incorporate some user feedback and I am having trouble figuring out how: I have a detail view: Enter code here... #views.py def detail(request, game_id): games = Game.objects.get(pk=game_id) context = { 'games':games} return render(request,'myapp/detail.html',context) Very simple with no form activity as of yet. My template currently shows a comparison between two properties set up like: #detail.html {{ games.roadTeam }} {{ games.roadTeamWins}} - {{ games.roadTeamLosses}} {{games.homeTeam }} {{ games.HomeTeamWins}} - {{ games.HomeTeamLosses}} I would like to work backwards and turn this template into a form. Would I be able to make it a form by adding a third div to each one of these that is a button which sends the value of the variable back to the view? and then how would I be able to process that in the view? Enter code here... {% csrf_token %} I am not an expert when it comes to forms, so your assistance would be greatly appreciated. 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/0569cc00-30c1-4b14-b521-107e37149340%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Django template iterating through two dictionaries/variables
I didn't really know how to label this question, but I think it's an interesting concept and I haven't seen a resolution anywhere else. I currently have two different dictionaries as context for a template: Enter code here...context ={ 'person':person, 'scores':scores, } Each of these dictionaries has a common key (person.Number), (scores.Number), however the person dictionary is based off of a model in my django database, while scores comes from a json feed that I parse through: I currently run through a table in a template that looks like this: Enter code here... Person Person Number First Name Last Name City Score {% for person in persons %} {{ person.Number }} {{ person.firstName }} {{ person.lastName }} {{ person.city }} ??'''scores.score1 goes here''' {% endfor %} What I'm trying to figure out to do is figure out how to get that final detail loaded into the table where we would find the score specific to that person.Number. In other words how to go through my scores dictionary in this template and find the corresponding score1 using the person.Number from the other dictionary as the value. Let me know if you have any ideas. 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/d05c8fc4-706b-422b-bc11-b656f1950dea%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Python dictionaries saved to models
Nevermind- the good folks at Django didn't add: from django.apps import apps in order to pull off this data migration On Thursday, August 18, 2016 at 8:40:26 AM UTC-5, Aaron Weisberg wrote: > > Thanks. > > However, when I write the function and try to run the data migration I run > into this error: > > Enter code here...NameError: name apps is not defined > > That is coming from this line in the migration: > > Players = apps.get_model("team","Players") > > This is a copy/paste from the documentation. Is there a typo? > > Thanks. > > > On Thursday, August 18, 2016 at 7:48:58 AM UTC-5, Tim Graham wrote: >> >> Right, or even in a standalone script if a migration is more than you >> need: >> https://docs.djangoproject.com/en/stable/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage >> >> On Thursday, August 18, 2016 at 2:14:39 AM UTC-4, Todor Velichkov wrote: >>> >>> Maybe a data migration >>> <https://docs.djangoproject.com/en/1.9/topics/migrations/#data-migrations> >>> is what you are looking for. >>> >>> On Thursday, August 18, 2016 at 8:38:33 AM UTC+3, Aaron Weisberg wrote: >>>> >>>> Great- thanks Tim. >>>> >>>> I understand the Python, but what I guess where I'm fuzzy is where to >>>> exactly put that code. >>>> >>>> Do I put it in the models.py? class.py? and how do I execute? >>>> >>>> That is the final piece of the puzzle for me. >>>> >>>> Thanks so much. >>>> >>>> Aaron >>>> >>>> On Wednesday, August 17, 2016 at 3:48:18 PM UTC-5, Tim Graham wrote: >>>>> >>>>> You need to transform your data dictionary so that the keys match the >>>>> models field names and then you can use: >>>>> >>>>> players_data = [{'number': 1, ...}, {...}] >>>>> >>>>> for data in players_data: >>>>> Player.objects.bulk_create(**data) >>>>> >>>>> (or something similar with bulk_create()) >>>>> >>>>> >>>>> https://docs.djangoproject.com/en/stable/ref/models/querysets/#bulk-create >>>>> >>>>> On Wednesday, August 17, 2016 at 1:42:04 PM UTC-4, Aaron Weisberg >>>>> wrote: >>>>>> >>>>>> Hi everyone, >>>>>> >>>>>> I have several dictionaries that I would like to import into my >>>>>> django project database, but I can't figure out exactly how. >>>>>> >>>>>> I have tried to implement through fixtures, through views and through >>>>>> loaddata, but I must be doing something wrong at every turn- so if >>>>>> someone >>>>>> could suggest a workflow, it would really help me a lot! >>>>>> >>>>>> My data is currently in a list of dictionaries called data: >>>>>> >>>>>> Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht': >>>>>> 'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': >>>>>> 'university', 'number': 10, 'exp': 1}, >>>>>> >>>>>> >>>>>> each dictionary within that list is a "player" who I'd like to input >>>>>> his data into my model "Players" >>>>>> >>>>>> Enter code here... >>>>>> #models.py >>>>>> class Player(models.Model): >>>>>> >>>>>> number = models.CharField(max_length=2) >>>>>> player = models.CharField(max_length=50) >>>>>> position = models.CharField(max_length=2) >>>>>> height = models.CharField(max_length=50) >>>>>> weight = models.CharField(max_length=50) >>>>>> birth = models.DateField() >>>>>> exp = models.CharField(max_length=50) >>>>>> college = models.CharField(max_length=50) >>>>>> def __str__(self): >>>>>> return self.player >>>>>> >>>>>> >>>>>> There are about 500 players in that list of dictionaries above that I >>>>>> would like to insert into this model. >>>>>> >>>>>> 1) Can i run a function in the model above to insert the data into >>>>>> its appropriate field? If so, how do
Re: Python dictionaries saved to models
Thanks. However, when I write the function and try to run the data migration I run into this error: Enter code here...NameError: name apps is not defined That is coming from this line in the migration: Players = apps.get_model("team","Players") This is a copy/paste from the documentation. Is there a typo? Thanks. On Thursday, August 18, 2016 at 7:48:58 AM UTC-5, Tim Graham wrote: > > Right, or even in a standalone script if a migration is more than you > need: > https://docs.djangoproject.com/en/stable/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage > > On Thursday, August 18, 2016 at 2:14:39 AM UTC-4, Todor Velichkov wrote: >> >> Maybe a data migration >> <https://docs.djangoproject.com/en/1.9/topics/migrations/#data-migrations> >> is what you are looking for. >> >> On Thursday, August 18, 2016 at 8:38:33 AM UTC+3, Aaron Weisberg wrote: >>> >>> Great- thanks Tim. >>> >>> I understand the Python, but what I guess where I'm fuzzy is where to >>> exactly put that code. >>> >>> Do I put it in the models.py? class.py? and how do I execute? >>> >>> That is the final piece of the puzzle for me. >>> >>> Thanks so much. >>> >>> Aaron >>> >>> On Wednesday, August 17, 2016 at 3:48:18 PM UTC-5, Tim Graham wrote: >>>> >>>> You need to transform your data dictionary so that the keys match the >>>> models field names and then you can use: >>>> >>>> players_data = [{'number': 1, ...}, {...}] >>>> >>>> for data in players_data: >>>> Player.objects.bulk_create(**data) >>>> >>>> (or something similar with bulk_create()) >>>> >>>> >>>> https://docs.djangoproject.com/en/stable/ref/models/querysets/#bulk-create >>>> >>>> On Wednesday, August 17, 2016 at 1:42:04 PM UTC-4, Aaron Weisberg wrote: >>>>> >>>>> Hi everyone, >>>>> >>>>> I have several dictionaries that I would like to import into my django >>>>> project database, but I can't figure out exactly how. >>>>> >>>>> I have tried to implement through fixtures, through views and through >>>>> loaddata, but I must be doing something wrong at every turn- so if >>>>> someone >>>>> could suggest a workflow, it would really help me a lot! >>>>> >>>>> My data is currently in a list of dictionaries called data: >>>>> >>>>> Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht': >>>>> 'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': >>>>> 'university', 'number': 10, 'exp': 1}, >>>>> >>>>> >>>>> each dictionary within that list is a "player" who I'd like to input >>>>> his data into my model "Players" >>>>> >>>>> Enter code here... >>>>> #models.py >>>>> class Player(models.Model): >>>>> >>>>> number = models.CharField(max_length=2) >>>>> player = models.CharField(max_length=50) >>>>> position = models.CharField(max_length=2) >>>>> height = models.CharField(max_length=50) >>>>> weight = models.CharField(max_length=50) >>>>> birth = models.DateField() >>>>> exp = models.CharField(max_length=50) >>>>> college = models.CharField(max_length=50) >>>>> def __str__(self): >>>>> return self.player >>>>> >>>>> >>>>> There are about 500 players in that list of dictionaries above that I >>>>> would like to insert into this model. >>>>> >>>>> 1) Can i run a function in the model above to insert the data into its >>>>> appropriate field? If so, how do I execute that function? >>>>> 2) If it's a view that I need to execute- do I just put the function >>>>> in views.py? How then is the dictionary imported into the database? >>>>> >>>>> or... How would you go about getting that data into your database? >>>>> Please note that the data is coming from a url that might change from >>>>> time >>>>> to time. But I think once i get the first iteration of data into these >>>>> models I can figure out how to update. But the only way I can figure out >>>>> is to create them one by one in the shell or create a form and input them >>>>> one by one. >>>>> >>>>> If you have a solution, please share and be as detailed as possible >>>>> since I am a complete beginner with django. >>>>> >>>>> Peace and love, >>>>> >>>>> Aaron >>>>> >>>>> -- 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/56a0c926-853b-42ba-ae25-9fa24d6f3bd1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Python dictionaries saved to models
Great- thanks Tim. I understand the Python, but what I guess where I'm fuzzy is where to exactly put that code. Do I put it in the models.py? class.py? and how do I execute? That is the final piece of the puzzle for me. Thanks so much. Aaron On Wednesday, August 17, 2016 at 3:48:18 PM UTC-5, Tim Graham wrote: > > You need to transform your data dictionary so that the keys match the > models field names and then you can use: > > players_data = [{'number': 1, ...}, {...}] > > for data in players_data: > Player.objects.bulk_create(**data) > > (or something similar with bulk_create()) > > https://docs.djangoproject.com/en/stable/ref/models/querysets/#bulk-create > > On Wednesday, August 17, 2016 at 1:42:04 PM UTC-4, Aaron Weisberg wrote: >> >> Hi everyone, >> >> I have several dictionaries that I would like to import into my django >> project database, but I can't figure out exactly how. >> >> I have tried to implement through fixtures, through views and through >> loaddata, but I must be doing something wrong at every turn- so if someone >> could suggest a workflow, it would really help me a lot! >> >> My data is currently in a list of dictionaries called data: >> >> Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht': >> 'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': >> 'university', 'number': 10, 'exp': 1}, >> >> >> each dictionary within that list is a "player" who I'd like to input his >> data into my model "Players" >> >> Enter code here... >> #models.py >> class Player(models.Model): >> >> number = models.CharField(max_length=2) >> player = models.CharField(max_length=50) >> position = models.CharField(max_length=2) >> height = models.CharField(max_length=50) >> weight = models.CharField(max_length=50) >> birth = models.DateField() >> exp = models.CharField(max_length=50) >> college = models.CharField(max_length=50) >> def __str__(self): >> return self.player >> >> >> There are about 500 players in that list of dictionaries above that I >> would like to insert into this model. >> >> 1) Can i run a function in the model above to insert the data into its >> appropriate field? If so, how do I execute that function? >> 2) If it's a view that I need to execute- do I just put the function in >> views.py? How then is the dictionary imported into the database? >> >> or... How would you go about getting that data into your database? >> Please note that the data is coming from a url that might change from time >> to time. But I think once i get the first iteration of data into these >> models I can figure out how to update. But the only way I can figure out >> is to create them one by one in the shell or create a form and input them >> one by one. >> >> If you have a solution, please share and be as detailed as possible since >> I am a complete beginner with django. >> >> Peace and love, >> >> Aaron >> >> -- 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/44dbbe95-c5ae-4282-8e70-d9e5795720e3%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Python dictionaries saved to models
Hi everyone, I have several dictionaries that I would like to import into my django project database, but I can't figure out exactly how. I have tried to implement through fixtures, through views and through loaddata, but I must be doing something wrong at every turn- so if someone could suggest a workflow, it would really help me a lot! My data is currently in a list of dictionaries called data: Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht': 'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': 'university', 'number': 10, 'exp': 1}, each dictionary within that list is a "player" who I'd like to input his data into my model "Players" Enter code here... #models.py class Player(models.Model): number = models.CharField(max_length=2) player = models.CharField(max_length=50) position = models.CharField(max_length=2) height = models.CharField(max_length=50) weight = models.CharField(max_length=50) birth = models.DateField() exp = models.CharField(max_length=50) college = models.CharField(max_length=50) def __str__(self): return self.player There are about 500 players in that list of dictionaries above that I would like to insert into this model. 1) Can i run a function in the model above to insert the data into its appropriate field? If so, how do I execute that function? 2) If it's a view that I need to execute- do I just put the function in views.py? How then is the dictionary imported into the database? or... How would you go about getting that data into your database? Please note that the data is coming from a url that might change from time to time. But I think once i get the first iteration of data into these models I can figure out how to update. But the only way I can figure out is to create them one by one in the shell or create a form and input them one by one. If you have a solution, please share and be as detailed as possible since I am a complete beginner with django. Peace and love, Aaron -- 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/83fa4e0a-c2b7-4c11-a78e-bd58c5df18b4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.