Sam Kerr
Sam Kerr

Reputation: 13

How do you make a django field reference to a python class?

I am working on a project to expand a testing suite that my company uses. One of this things that was asked of me was to link the website to our Github source for code so that the dev team could continue tracking the issues there instead of trying to look in two places. I was able to do this but the problem is that every time the a bug is reported an issue is opened.

I want to add a field to my Django model that tracks an Issue object (from the github3.py wrapper) that is sent to Github. I want to use this to check if an Issue has already been created in Github by that instance of the BugReport and if it has been created, edit the Issue instead of creating another issue in Github that is a duplicate. Does Django have a something that can handle this sort of reference?

I am using Django 1.3.1 and Python 2.7.1

EDIT

I was able to figure my specific problem out using esauro's suggestions. However, as mkoistinen said, If this problem came up in a program where the work-around was not as easy as this one was, should an object reference be created like I had originally asked about or is that bad practice? and if it is okay to make an object reference like that, how would you do it with the Django models?

Upvotes: 1

Views: 151

Answers (1)

Ian Stapleton Cordasco
Ian Stapleton Cordasco

Reputation: 28757

I'm the creator of github3.py.

If you want to get the issue itself via a number, there are a couple different ways to do this. I'm not sure how you're interacting with the API but you can do:

import github3


i = githbu3.issue('repo_owner', 'repo_name', issue_number)

or

import github3


r = github3.repository('repo_owner', 'repo_name')
i = r.issue(issue_number)

or

import github3


g = github3.login(client_key='client_key', client_secret='client_secret')
i = g.issue('repo_owner', 'repo_name', issue_number)
# or
r = g.repository('repo_owner', 'repo_name')
i = r.issue(issue_number)

otherwise if you're looking for something that's in an issue without knowing the number:

import github3


r = github3.repository('repo_owner', 'repo_name')
for i in r.iter_issues():
    if 'text to search for' in i.body_text:
        i.edit('...')

Upvotes: 0

Related Questions