我有以下型号:
class RepoDetails(models.Model):
owner = models.ForeignKey(Owner, default='your repo username')
repo_name = models.CharField(max_length=50)
repo_username = models.CharField(max_length=50)
repo_password = models.CharField(max_length=50)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, blank=True, null=True)
def __str__(self):
return ' '.join([self.repo_name, self.repo_username])
在我看来,我有这个:
def get_repo_data(request):
url = 'https://api.bitbucket.org/1.0/user/'
repositories = RepoDetails.objects.filter(owner=request.user)
username = repositories.repo_username
password = repositories.repo_password
name = repositories.repo_name
repo_data = requests.get(url, auth=(username, password)).json()
date = get_repo_last_updated(repo_data, name=name)
updated = repositories.updated.get_or_create(updated=date)
# update = time.strftime('%Y-%m-%d %H:%M:%S', time.strptime(tweet['created_at'],'%a %b %d %H:%M:%S +0000 %Y'))
template = 'repository/repositories_status.html'
return render(request, template, {'repo_updated': date})
def get_repo_last_updated(data, name):
return next((d for d in data['repositories'] if d['name'] == name), {}).get('utc_last_updated')
我想通过访问API检查我的存储库的状态,然后从JSON中获取' utc_last_updated'并检查日期值。如果它比存储的更新字段更新,那么它应该替换并保存最新的字段。
然而,现在似乎没有任何上述工作。用户名和密码是您使用的Bitbucket用户名和密码。
如何解决此问题?